Kazulka Kazulka - 2 years ago 193
Python Question

Working with checkboxes in tkinter (pygubu)

I created a window with the GUI maker pygubu. This window contains checkboxes. But my script is not able to recognize if the checkboxes are marked or not.
How do I have to check if the checkboxes are marked or not?
Do Ihave to use the command or the variable? What is the right syntax?

Below you can see what I have done in pygubu. How do I get the state of my checkbox?

I tried:

def checker13(self, variable=check13):
self.variable13 = variable
print self.variable13

This should print me the state of the checkbox everytime something changed. But I always receive an error. What can I do?

Answer Source

Finally I found an inelegant way to do it. It's not very "pretty", but it works:

self.xxx1 = 0 
def checker13(self):
    if self.xxx1 == 0:
        self.xxx1 = self.xxx1+1
        self.xxx1 = 0 

Normally the checkbox is not marked and the value is 0. If the checkbox gets marked there is an event and the value changes to 1. The next event changes the value back to 0. By this method I can check the state of the checkbox by checking xxx1.

I knew there are other ways (with IntVar()) but I was specifically searching for a solution with pygubu. If there is a smoother answer feel free to correct me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download