vendredi 6 février 2015

How to create a button to save the state of a checkbutton in python?

I am using tkinter in python 3. I have a checkbutton and button on my GUI:



entercheck = Checkbutton(self, variable = value)
entercheck.pack()
savebutton = Button(self, width=5, height=2, command = savecheck)
savebutton.pack()


where value=IntVar(). I am trying to make it so that when clicked, the button saves the status of the checkbutton to the variable status. I have tried:



def savecheck():
status = value.get()


However, this always results in status being equal to 0 no matter whether the checkbutton is checked or not. Why is this?


I have had a look at this question: Getting Tkinter Check Box State and this method seems to be working for them?





Aucun commentaire:

Enregistrer un commentaire