1 """Ttk Theme Selector v2.
3 This is an improvement from the other theme selector (themes_combo.py)
4 since now you can notice theme changes in Ttk Combobox, Ttk Frame,
5 Ttk Label and Ttk Button.
12 ttk
.Frame
.__init
__(self
, borderwidth
=3)
14 self
.style
= ttk
.Style()
16 # XXX Ideally I wouldn't want to create a Tkinter.IntVar to make
17 # it works with Checkbutton variable option.
18 self
.theme_autochange
= Tkinter
.IntVar(self
, 0)
21 def _change_theme(self
):
22 self
.style
.theme_use(self
.themes_combo
.get())
24 def _theme_sel_changed(self
, widget
):
25 if self
.theme_autochange
.get():
28 def _setup_widgets(self
):
29 themes_lbl
= ttk
.Label(self
, text
="Themes")
31 themes
= self
.style
.theme_names()
32 self
.themes_combo
= ttk
.Combobox(self
, values
=themes
, state
="readonly")
33 self
.themes_combo
.set(themes
[0])
34 self
.themes_combo
.bind("<<ComboboxSelected>>", self
._theme
_sel
_changed
)
36 change_btn
= ttk
.Button(self
, text
='Change Theme',
37 command
=self
._change
_theme
)
39 theme_change_checkbtn
= ttk
.Checkbutton(self
,
40 text
="Change themes when combobox item is activated",
41 variable
=self
.theme_autochange
)
43 themes_lbl
.grid(ipadx
=6, sticky
="w")
44 self
.themes_combo
.grid(row
=0, column
=1, padx
=6, sticky
="ew")
45 change_btn
.grid(row
=0, column
=2, padx
=6, sticky
="e")
46 theme_change_checkbtn
.grid(row
=1, columnspan
=3, sticky
="w", pady
=6)
48 top
= self
.winfo_toplevel()
49 top
.rowconfigure(0, weight
=1)
50 top
.columnconfigure(0, weight
=1)
51 self
.columnconfigure(1, weight
=1)
52 self
.grid(row
=0, column
=0, sticky
="nsew", columnspan
=3, rowspan
=2)
57 app
.master
.title("Theme Selector")
60 if __name__
== "__main__":