forked from MorvanZhou/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtk5_radiobutton.py
33 lines (25 loc) · 928 Bytes
/
tk5_radiobutton.py
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
# View more python learning tutorial on my Youtube and Youku channel!!!
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial
import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('200x200')
var = tk.StringVar()
l = tk.Label(window, bg='yellow', width=20, text='empty')
l.pack()
def print_selection():
l.config(text='you have selected ' + var.get())
r1 = tk.Radiobutton(window, text='Option A',
variable=var, value='A',
command=print_selection)
r1.pack()
r2 = tk.Radiobutton(window, text='Option B',
variable=var, value='B',
command=print_selection)
r2.pack()
r3 = tk.Radiobutton(window, text='Option C',
variable=var, value='C',
command=print_selection)
r3.pack()
window.mainloop()