Python中Tk的背景颜色设置
我正在用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)
5 个回答
5
config
是另外一个选择:
widget1.config(bg='black')
widget2.config(bg='#000000')
或者:
widget1.config(background='black')
widget2.config(background='#000000')
26
我知道这个问题有点老了,不过:
root["bg"] = "black"
这个方法也能达到你想要的效果,而且输入的内容更少。
134
root.configure(background='black')
<widget>.configure(background='black')
或者更一般来说