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!
The LabelFrame widget, like the Frame widget, is a spatial container—a rectangular area that can contain other widgets. However, unlike the Frame widget, the LabelFrame widget allows you to display a label as part of the border around the area.
A labelframe is a simple container widget. Its primary purpose is to act as a spacer or container for complex window layouts. This widget has the features of a frame plus the ability to display a label.
The Checkbutton widget is used to display a number of options to a user as toggle buttons. The user can then select one or more options by clicking the button corresponding to each option. You can also display images in place of text.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With