Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Demo / tkinter / ttk / theme_selector.py
blobadb8472e6393506791b16fc888ed19df7857c990
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.
6 """
7 import Tkinter
8 import ttk
10 class App(ttk.Frame):
11 def __init__(self):
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)
19 self._setup_widgets()
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():
26 self._change_theme()
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)
55 def main():
56 app = App()
57 app.master.title("Theme Selector")
58 app.mainloop()
60 if __name__ == "__main__":
61 main()