-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTkinter_RadioButton.py
36 lines (30 loc) · 976 Bytes
/
Tkinter_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
34
35
36
from tkinter import *
def sel():
selection = "You selected the option " + str(v.get())
lab.config(text = selection)
rt=Tk()
v=IntVar()
r1=Radiobutton(rt,text='Option 1',variable=v,value=1,command=sel).pack()
r2=Radiobutton(rt,text='Option 2',variable=v,value=2,command=sel).pack()
r3=Radiobutton(rt,text='Option 3',variable=v,value=3,command=sel).pack()
lab=Label(rt)
lab.pack()
rt.mainloop()
#===========================================================
# def sel():
# selection = "You selected the option " + str(var.get())
# label.config(text = selection)
# root = Tk()
# var = IntVar()
# R1 = Radiobutton(root, text="Option 1", variable=var, value=1,
# command=sel)
# R1.pack( anchor = W )
# R2 = Radiobutton(root, text="Option 2", variable=var, value=2,
# command=sel)
# R2.pack( anchor = W )
# R3 = Radiobutton(root, text="Option 3", variable=var, value=3,
# command=sel)
# R3.pack( anchor = W)
# label = Label(root)
# label.pack()
# root.mainloop()