Advertisement
here2share

# checkbutton_group_io.py

Jun 3rd, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # checkbutton_group_io
  2.  
  3. from Tkinter import *
  4. root = Tk()
  5. a='a'
  6. b='b'
  7. label = {}
  8. root.grid_rowconfigure(0,weight=1)
  9. root.grid_columnconfigure(0,weight=1)
  10. root.config(background="lavender")
  11. label[a] = Label(root, bg='yellow')
  12. label[a].pack(side='left')
  13. label[b] = Label(root, bg='blue')
  14. label[b].pack(side='right')
  15. button = {}
  16. aaa = IntVar()
  17. bbb = IntVar()
  18. def click(item,var):
  19.     if var.get():
  20.         io='disabled'
  21.     else:
  22.         io='normal'
  23.     for w in label[item].winfo_children()[1:]:
  24.         w.configure(state=io)
  25. def fn(e):
  26.     print e
  27. check_a = Checkbutton(label[a], text=" Group A ", variable=aaa, command=lambda e=a, v=aaa: click(e,v))
  28. check_a.grid(row=0, column=0)
  29. for i in range(5):
  30.     button[b] = Button(label[a], text='Button '+str(i), command=lambda e='Group A: '+str(i): fn(e))
  31.     button[b].grid(row=i+1, column=0)
  32. check_b = Checkbutton(label[b], text=" Group B ", variable=bbb, command=lambda e=b, v=bbb: click(e,v))
  33. check_b.grid(row=0, column=1)
  34. for i in range(5):
  35.     button[a] = Button(label[b], text='Button '+str(i), command=lambda e='Group B: '+str(i): fn(e))
  36.     button[a].grid(row=i+1, column=1)
  37. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement