if statement - Python, Tkinter, Checkbutton: Is there a way to check on/off value -


What am I trying to do, if the statements are to check whether the checkbutton value is on or off

What I was thinking is something like

  to def import from checkin 'value (): # if the statement is given here # then some like them #if checkbox_1.onvalue == True: # checkbox_2degct () #if checkbox_1.varible == checkbox_1.onvalue: # checkbox_2.deselect () print lines' 7-8 or 10-11 'root is needed' root = Tk () checkbox = CheckButton (root, target CST = "1", command = Chekbutn_muly) Kpak () Chekboks_2 = Chekbutn (root, text = "2", command = Chekbutn_muly). Pack () checkbox_3 = checkbootan (root, text = 'quoted', command = left). Pack () Route. Mainloop ()    

First of all, create a single widget and do not pack Line . Pack returns none , so above your code, checkbox_1 is none . Instead:

  checkbox = checkboot (root, text = '1', command = checkboot_value) checkbox_1.pack ()   

Now, get value To check button:

  def checkboot_name1 (): if (var1.get ()): var2.set (0) def checkboot_value2 (): if (var2.get ()) : Var1 set (0) var1 = Intvar () checkbox = = checkbootan (root, text = '1', variable = var1, command = checkboot_valued1) checkbox_1.pack () var2 = IntVar () checkbox_2 = checkbooten (root , Text = '2', variable = var2, command = checkbutton_value2) checkbox_2.pack ()   

often for such things There is a desire to create the check button class:

  class MyCheckButton (check button): def __init __ (self, * args, ** kwargs): self.var = kwargs.get ('variable' Intvar ()) kwargs ['variable'] = self.var check button .__ init __ (self, * args, ** kwargs) def is_checked (auto): return self.var.get ()    

Comments