samedi 4 février 2017

How to re-evaluate state of checkbutton in tkinter

I can't seem to re-evaluate the state of a checkbox. In a simple explination, I can do the following

import tkinter
from tkinter imprt ttk
root = Tk()
ck = ttk.Checkbutton(root, text='Checkbox')
ck.state(['!alternate'])
ck.state(['selected'])

if ck.instate(['selected']):
    # do something
elif ck.instate(['!selected']):
    # do something else

root.mainloop()

This sets the checkbutton to a 'selected' state, and then runs the if statement because it is selected. However, if I were to unselect that checkbox, it doesn't re-evaluate the state of the checkbox and run the elif statement. I've looked at things like root.update() or root.update_idletasks, but I'm fairly certain this isn't what I'm looking for.

Thanks for any help!

As a side note, I'm on Python 3.x

Aucun commentaire:

Enregistrer un commentaire