我正在用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