Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set style for Checkbutton or Labelframe in python tkinter

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!

like image 342
Mark Jie Avatar asked Sep 12 '13 05:09

Mark Jie


People also ask

What is the difference between frame and LabelFrame in tkinter?

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.

What is LabelFrame in tkinter?

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.

What is Checkbutton in tkinter?

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.


1 Answers

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()
like image 146
Oblivion Avatar answered Sep 20 '22 11:09

Oblivion