在 python tkinter 中设置 Checkbutton 或 Labelframe 的样式 [英] Set style for Checkbutton or Labelframe in python tkinter

查看:42
本文介绍了在 python tkinter 中设置 Checkbutton 或 Labelframe 的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 python tkinter 设计了一个 GUI.现在我想为 Checkbutton 和 Labelframe 设置样式,例如字体、颜色等我已经阅读了一些关于 tkinter 样式主题的答案,并且我使用以下方法为 Checkbutton 和 Labelframe 设置样式.但它们实际上不起作用.

I have designed a GUI using python tkinter. And now I want to set style for Checkbutton and Labelframe, such as the font, the color .etc I have read some answers on the topics of tkinter style, and I have used the following method to set style for both Checkbutton and Labelframe. But they don't actually work.

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")

你能告诉我原因吗,或者你有其他一些有效的方法吗?非常感谢!

Can you tell me the reasons, or do you have some other valid methods? Thank you very much!

推荐答案

需要配置Label子组件:

You need to configure the Label sub-component:

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 tkinter 中设置 Checkbutton 或 Labelframe 的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆