here2share

# Tk_group_RadioButtons.py

Sep 30th, 2020
864
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_group_RadioButtons.py
  2.  
  3. import Tkinter as tk
  4.  
  5. win = tk.Tk()
  6.  
  7. def show_values():
  8.     a = " : ".join([('???','Yes','No')[i.get()] for i in values])
  9.     r = tk.Label(win, text=a)
  10.     r.grid(column=0, row=last_row,columnspan=3)
  11. def reset_values():
  12.     [value.set(0) for value in values]
  13.  
  14. rbtns = ["RB1: ", "RB2: ", "RB3: "]
  15. values = [tk.IntVar() for i in range(len(rbtns))]
  16. i = 0
  17. for r in rbtns:
  18.     r1 = tk.Radiobutton(win, text="Yes", variable=values[i], value=1)
  19.     r2 = tk.Radiobutton(win, text="No", variable=values[i], value=2)
  20.     r1.grid(column=1, row=i)
  21.     r2.grid(column=2, row=i)
  22.  
  23.     item_Label = tk.Label(win, text=r)
  24.     item_Label.grid(column=0, row=i)
  25.     i += 1
  26. last_row = i+2
  27.  
  28. tk.Button(win, text='Reset', command=reset_values).grid(sticky='we',columnspan=3)
  29. tk.Button(win, text='Show Values', command=show_values).grid(sticky='we',columnspan=3)
  30.  
  31. win.mainloop()
  32.  
RAW Paste Data