- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateRadioButtonWidget.py
More file actions
Latest commit
33 lines (24 loc) · 892 Bytes
/
Copy pathCreateRadioButtonWidget.py
File metadata and controls
33 lines (24 loc) · 892 Bytes
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
importtkinterastk
fromtkinterimportttk
win=tk.Tk()
win.title('Create Radio Button Widgets')
win.geometry('300x100')
# RadioButton Globals
COLOR1='Blue'
COLOR2='Gold'
COLOR3='Red'
# RadioButton Callback
defradCall():
radSel=radVar.get()
ifradSel==1: win.configure(background=COLOR1)
elifradSel==2: win.configure(background=COLOR2)
elifradSel==3: win.configure(background=COLOR3)
# create three RadioButtons using one variable
radVar=tk.IntVar()
rad1=tk.Radiobutton(win, text=COLOR1, variable=radVar, value=1, command=radCall)
rad1.grid(column=0, row=1, sticky=tk.W)
rad2=tk.Radiobutton(win, text=COLOR2, variable=radVar, value=2, command=radCall)
rad2.grid(column=1, row=1, sticky=tk.W)
rad3=tk.Radiobutton(win, text=COLOR3, variable=radVar, value=3, command=radCall)
rad3.grid(column=2, row=1, sticky=tk.W)
win.mainloop()