Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_group_RadioButtons.py
- import Tkinter as tk
- win = tk.Tk()
- def show_values():
- a = " : ".join([('???','Yes','No')[i.get()] for i in values])
- r = tk.Label(win, text=a)
- r.grid(column=0, row=last_row,columnspan=3)
- def reset_values():
- [value.set(0) for value in values]
- rbtns = ["RB1: ", "RB2: ", "RB3: "]
- values = [tk.IntVar() for i in range(len(rbtns))]
- i = 0
- for r in rbtns:
- r1 = tk.Radiobutton(win, text="Yes", variable=values[i], value=1)
- r2 = tk.Radiobutton(win, text="No", variable=values[i], value=2)
- r1.grid(column=1, row=i)
- r2.grid(column=2, row=i)
- item_Label = tk.Label(win, text=r)
- item_Label.grid(column=0, row=i)
- i += 1
- last_row = i+2
- tk.Button(win, text='Reset', command=reset_values).grid(sticky='we',columnspan=3)
- tk.Button(win, text='Show Values', command=show_values).grid(sticky='we',columnspan=3)
- win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement