【发布时间】:2010-04-30 13:28:19
【问题描述】:
我正在用 Tkinter 编写一个幻灯片程序,但我不知道如何将背景颜色更改为黑色而不是标准的浅灰色。如何做到这一点?
import os, sys
import Tkinter
import Image, ImageTk
import time
root = Tkinter.Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.focus_set()
root.bind("<Escape>", lambda e: e.widget.quit())
image = Image.open(image_path+f)
tkpi = ImageTk.PhotoImage(image)
label_image = Tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=w,height=h)
root.mainloop(0)
【问题讨论】:
-
背景是什么?一个小部件?使用
background关键字。更多信息:pythonware.com/library/tkinter/introduction/widget-styling.htm -
许多 Tk 小部件都有 bg 属性,允许指定它们的背景颜色。
-
好吧,我对 Tk 很陌生,所以我不确定小部件到底是什么,但 label_image.configure(background='black') 成功了。在这种情况下 label_image 是一个小部件还是只是根?
-
经典 Tk 小部件具有该属性。主题往往不会;小部件的背景颜色是那里的样式/主题的属性。