File tree 2 files changed +60
-0
lines changed 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
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 ()
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments