test_themes.py
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
# root window
self.title('Theme Demo')
self.geometry('400x300')
self.style = ttk.Style(self)
# label
label = ttk.Label(self, text='Name:')
label.grid(column=0, row=0, padx=10, pady=10, sticky='w')
# entry
textbox = ttk.Entry(self)
textbox.grid(column=1, row=0, padx=10, pady=10, sticky='w')
# button
btn = ttk.Button(self, text='Show')
btn.grid(column=2, row=0, padx=10, pady=10, sticky='w')
# radio button
self.selected_theme = tk.StringVar()
theme_frame = ttk.LabelFrame(self, text='Themes')
theme_frame.grid(padx=10, pady=10, ipadx=20, ipady=20, sticky='w')
for theme_name in self.style.theme_names():
rb = ttk.Radiobutton(
theme_frame,
text=theme_name,
value=theme_name,
variable=self.selected_theme,
command=self.change_theme)
rb.pack(expand=True, fill='both')
def change_theme(self):
self.style.theme_use(self.selected_theme.get())
if __name__ == "__main__":
app = App()
app.mainloop()