- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddingWidgetsOnALoop.py
More file actions
Latest commit
30 lines (21 loc) · 790 Bytes
/
Copy pathAddingWidgetsOnALoop.py
File metadata and controls
30 lines (21 loc) · 790 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
importtkinterastk
fromtkinterimportttk
fromtkinterimportIntVar
win=tk.Tk()
win.title('Create Radio Button With a Loop')
colors= ['Blue','Gold','Red']
defradCall():
radSel=radVar.get()
ifradSel==0: win.configure(background=colors[0])
elifradSel==1: win.configure(background=colors[1])
elifradSel==2: win.configure(background=colors[2])
#create 3 Radiobuttons using one variable
radVar=tk.IntVar()
# next select a non-existing index value for radVar.
radVar.set(99)
# now create all 3 Radiobuttons widgets with one loop
forcolinrange(3):
curRad='rad'+str(col)
curRad=tk.Radiobutton(win, text=colors[col], variable=radVar, value=col, command=radCall)
curRad.grid(column=col, row=6, sticky=tk.W)
win.mainloop()