在Python 2.7中更改Tkinter窗口的背景颜色

时间:2018-04-20 14:20:55

标签: python python-2.7 tkinter themes

我正在使用函数tkFileDialog.askopenfilename()要求用户选择文件路径。问题是,由于我使用的黑暗主题,文字是浅灰色。窗口的背景应该是黑色的(在系统的其余部分它是黑色的),但由于某些原因在tkinter窗口中它仍然是白色的。这是一个截图:

enter image description here

如您所见,文字几乎无法读取。

我尝试使用.configure(background='black')更改窗口背景的颜色,但没有成功......有人可以帮忙吗?

非常感谢!

编辑:或者,我也很乐意将文字颜色改为黑色......白色不是浅灰色!

1 个答案:

答案 0 :(得分:0)

从tkinter的源代码中我看不到任何允许为askopenfilename()更改背景的选项。

来自代码:

# For the following classes and modules:
#
# options (all have default values):
#
# - defaultextension: added to filename if not explicitly given
#
# - filetypes: sequence of (label, pattern) tuples.  the same pattern
#   may occur with several patterns.  use "*" as pattern to indicate
#   all files.
#
# - initialdir: initial directory.  preserved by dialog instance.
#
# - initialfile: initial file (ignored by the open dialog).  preserved
#   by dialog instance.
#
# - parent: which window to place the dialog on top of
#
# - title: dialog title
#
# - multiple: if true user may select more than one file
#
# options for the directory chooser:
#
# - initialdir, parent, title: see above
#
# - mustexist: if true, user must pick an existing directory
#