简体   繁体   English

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

[英]Change background color of Tkinter window in Python 2.7

I am using the function tkFileDialog.askopenfilename() to ask the user to choose a file path. 我正在使用函数tkFileDialog.askopenfilename()来要求用户选择文件路径。 The problem is that, due to a dark theme I am using, the text is light grey. 问题是,由于我使用的是深色主题,因此文本为浅灰色。 The background of the window should be black (it is black in the rest of the system), but for some reason in the tkinter window it remains white. 窗口的背景应该是黑色的(在系统的其余部分是黑色的),但是由于某些原因,在tkinter窗口中它仍然是白色的。 Here is a screenshot: 这是屏幕截图:

在此处输入图片说明

As you can see, the text is barely readable. 如您所见,文本几乎不可读。

I tried to change the color of the background of the window using .configure(background='black') but with no success... can anybody help? 我尝试使用.configure(background='black')更改窗口背景的颜色,但没有成功...有人可以帮忙吗?

Thank you very much! 非常感谢你!

Edit: alternatively, I would also be happy to change the color of the text to black... just not light grey on white! 编辑:或者,我也很乐意将文本的颜色更改为黑色...只是在白色时不是浅灰色!

From the source code in tkinter I do not see any options that allow for the background to be changed for askopenfilename() . askopenfilename()的源代码中,我看不到任何允许对askopenfilename()的背景进行更改的askopenfilename()

From the code: 从代码:

# 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
#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM