我正在用Tkinter编写幻灯片程序,但我不知道如何将背景颜色更改为黑色而不是标准浅灰色。如何才能做到这一点?Python中Tk的背景颜色
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)
的背景是什么?一个小部件?使用'背景'关键字。更多信息:http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm – 2010-04-30 13:52:43
许多Tk窗口小部件都有bg属性,它允许指定它们的背景颜色。 – sastanin 2010-04-30 13:57:47
嗯,我对Tk非常陌生,所以我不确定小部件究竟是什么,但是label_image.configure(background ='black')取得了诀窍。在这种情况下,label_image是一个小部件,还是仅仅是root? – olofom 2010-04-30 18:26:42