Skip to content

Commit ffb288a

Browse files
committed
checkbutton-listbox-optionmenu
1 parent 82c0876 commit ffb288a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## example-1.py
3+
4+
![#1](screenshots/image-1.png?raw=true)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
3+
import tkinter as tk
4+
5+
# --- functions ---
6+
7+
def on_button():
8+
9+
# - OptionMenus -
10+
for i, var in enumerate(o_vars):
11+
print('OptionMenu {}: {}'.format(i, var.get()))
12+
13+
print('-------------------------')
14+
15+
# - Listbox -
16+
print('ListBox:', l.curselection())
17+
for i in l.curselection():
18+
print('option:', OPTIONS[i])
19+
20+
print('-------------------------')
21+
22+
# - Checkbuttons -
23+
print('ChecboxBox:')
24+
for i, var in enumerate(cb_vars):
25+
if var.get():
26+
print('option:', OPTIONS[i])
27+
28+
print('=========================')
29+
30+
# --- main ---
31+
32+
OPTIONS = ["Script 1", "Script 2", "Script 3", "Script 4", "Script 5"]
33+
34+
root = tk.Tk()
35+
36+
# - OptionMenu -
37+
38+
tk.Label(root, text='OptionMenus', bg='#aaa').pack(fill='x')
39+
40+
o_vars = []
41+
42+
for i in range(3):
43+
var = tk.StringVar(value='- select -')
44+
o_vars.append(var)
45+
tk.OptionMenu(root, var, *OPTIONS).pack()
46+
47+
# - Listbox -
48+
49+
tk.Label(root, text='Listbox', bg='#aaa').pack(fill='x')
50+
51+
l = tk.Listbox(root, selectmode='multiple')
52+
l.pack()
53+
l.insert('end', *OPTIONS)
54+
55+
# - Checkbuttons -
56+
57+
tk.Label(root, text='Checkbuttons', bg='#aaa').pack(fill='x')
58+
59+
cb_vars = []
60+
61+
for option in OPTIONS:
62+
var = tk.BooleanVar(value=False)
63+
cb_vars.append(var)
64+
tk.Checkbutton(root, text=option, variable=var).pack()
65+
66+
# - Button -
67+
68+
b = tk.Button(root, text='OK', command=on_button)
69+
b.pack(fill='x')
70+
71+
# - start -
72+
73+
root.mainloop()
Loading

0 commit comments

Comments
 (0)