Skip to content

Commit ece33f2

Browse files
committed
OptionMenu
1 parent 87332b2 commit ece33f2

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tkinter/optionmenu/example-1.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import tkinter as tk
2+
3+
# --- functions ---
4+
5+
def on_change_selection(value):
6+
print(' value:', value)
7+
print('selected:', selected.get())
8+
9+
# --- main ---
10+
11+
root = tk.Tk()
12+
13+
# ---
14+
15+
options = ["one", "two", "three"]
16+
17+
selected = tk.StringVar(value=options[0])
18+
19+
#selected = tk.StringVar()
20+
#selected.set(options[0])
21+
22+
op = tk.OptionMenu(root, selected, *options, command=on_change_selection)
23+
op.pack()
24+
25+
# ---
26+
27+
root.mainloop()

tkinter/optionmenu/example-2.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import tkinter as tk
2+
3+
# --- functions ---
4+
5+
def on_change_selection(value):
6+
print(' value:', value, '--->', data[value])
7+
print('selected:', selected.get(), '--->', data[value])
8+
9+
# --- main ---
10+
11+
root = tk.Tk()
12+
13+
# ---
14+
15+
data = {
16+
"one": "Hello first World",
17+
"two": "Hello second World ",
18+
"three": "Hello third World",
19+
}
20+
21+
options = sorted(data)
22+
23+
selected = tk.StringVar(value=options[0])
24+
25+
#selected = tk.StringVar()
26+
#selected.set(options[0])
27+
28+
op = tk.OptionMenu(root, selected, *options, command=on_change_selection)
29+
op.pack()
30+
31+
# ---
32+
33+
root.mainloop()

0 commit comments

Comments
 (0)