| 1 |
"""Ttk Theme Selector. |
| 2 |
|
| 3 |
Although it is a theme selector, you won't notice many changes since |
| 4 |
there is only a combobox and a frame around. |
| 5 |
""" |
| 6 |
import ttk |
| 7 |
|
| 8 |
class App(ttk.Frame): |
| 9 |
def __init__(self): |
| 10 |
ttk.Frame.__init__(self) |
| 11 |
|
| 12 |
self.style = ttk.Style() |
| 13 |
self._setup_widgets() |
| 14 |
|
| 15 |
def _change_theme(self, event): |
| 16 |
if event.widget.current(): |
| 17 |
newtheme = event.widget.get() |
| 18 |
|
| 19 |
self.style.theme_use(newtheme) |
| 20 |
|
| 21 |
def _setup_widgets(self): |
| 22 |
themes = list(self.style.theme_names()) |
| 23 |
themes.insert(0, "Pick a theme") |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
themes_combo = ttk.Combobox(self, values=themes, state="readonly", |
| 28 |
height=4) |
| 29 |
themes_combo.set(themes[0]) |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
themes_combo.bind("<<ComboboxSelected>>", self._change_theme) |
| 35 |
themes_combo.pack(fill='x') |
| 36 |
|
| 37 |
self.pack(fill='both', expand=1) |
| 38 |
|
| 39 |
|
| 40 |
def main(): |
| 41 |
app = App() |
| 42 |
app.master.title("Ttk Combobox") |
| 43 |
app.mainloop() |
| 44 |
|
| 45 |
if __name__ == "__main__": |
| 46 |
main() |