有人知道默认背景的颜色代码吗?我在程序中更改了背景颜色,现在需要将其恢复为默认颜色,但是我找不到颜色代码。
任何帮助都将不胜感激。谢谢。
有人知道默认背景的颜色代码吗?我在程序中更改了背景颜色,现在需要将其恢复为默认颜色,但是我找不到颜色代码。
任何帮助都将不胜感激。谢谢。
试试这个:
root.configure(background='SystemButtonFace')
如果您想在运行时获取默认背景,可以使用 cget
方法。这可能返回一个颜色名称,而不是一个 RGB 值。
import Tkinter as tk
root = tk.Tk()
bg = root.cget("background")
# eg: 'systemWindowBody'
rgb = root.winfo_rgb(bg)
# eg: (65535, 65535, 65535)
color = "#%x%x%x" % rgb
# eg: '#ffffffffffff'
在更改背景后重置它,请保存值,然后使用该值与configure
命令一起使用:
original_background = root.cget("background")
...
root.configure(background=original_background)
另一个选择是仅清除background
设置。例如:
import Tkinter as tk
root = tk.Tk()
lbl_status = ttk.Label(root, width=20, text="Some Text")
lbl_status['background'] = 'yellow' # Set background to yellow
lbl_status['background'] = '' # Reset it to system default
rgb
值吗? - user2705585