Set style for Checkbutton or Labelframe in python tkinter

后端 未结 2 1779
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 06:16

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 topi

2条回答
  •  Happy的楠姐
    2021-01-18 06:55

    As the accepted answer didn't really help me when I wanted to do a simple changing of weight of a ttk.LabelFrame font (if you do it like recommended, you end up with a misplaced label), I'll provide what worked for me.

    You have to use labelwidget option argument of ttk.LabelFrame first preparing a seperate ttk.Label that you style earlier accordingly. Important: using labelwidget means you don't use the usual text option argument for your ttk.LabelFrame (just do it in the label).

    # changing a labelframe font's weight to bold
    root = Tk()
    style = ttk.Style()
    style.configure("Bold.TLabel", font=("TkDefaultFont", 9, "bold"))
    label = ttk.Label(text="Foo", style="Bold.TLabel")
    lf = ttk.LabelFrame(root, labelwidget=label)
    

提交回复
热议问题