我使用 python tkinter 设计了一个 GUI。现在我想为 Checkbutton 和 Labelframe 设置样式,例如字体,颜色等 我已经阅读了一些关于 tkinter 样式主题的答案,并且我使用以下方法为 Checkbutton 和 Labelframe 设置样式。 但它们实际上不起作用。
Root = tkinter.Tk()
ttk.Style().configure('Font.TLabelframe', font="15", foreground = "red")
LabelFrame = ttk.Labelframe(Root, text = "Test", style = "Font.TLabelframe")
LabelFrame .pack( anchor = "w", ipadx = 10, ipady = 5, padx = 10, pady = 0, side = "top")
能告诉我原因吗,或者你有其他一些有效的方法吗?非常感谢!
最佳答案
需要配置Label子组件:
from tkinter import *
from tkinter import ttk
root = Tk()
s = ttk.Style()
s.configure('Red.TLabelframe.Label', font=('courier', 15, 'bold'))
s.configure('Red.TLabelframe.Label', foreground ='red')
s.configure('Red.TLabelframe.Label', background='blue')
lf = ttk.LabelFrame(root, text = "Test", style = "Red.TLabelframe")
lf.pack( anchor = "w", ipadx = 10, ipady = 5, padx = 10,
pady = 0, side = "top")
Frame(lf, width=100, height=100, bg='black').pack()
print(s.lookup('Red.TLabelframe.Label', 'font'))
root.mainloop()
关于python - 在 python tkinter 中为 Checkbutton 或 Labelframe 设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18755963/