mercredi 5 septembre 2018

Tkinter Checkbutton appearance not updating until mouse leave button's area

I want to change a TKinter.Checkbutton's value when it is being clicked.

The button is a Checkbutton and I use an IntVar to track/change its value.

In the following example I just have one button and I want it to change state back to 0 whenever we click on it (it can sound stupid in this case but I am trying to solve an other more complex case where more buttons change values).

The value is actually updated but the button's appearance does not change until the mouse leaves what seems to be the button's area.

Here is the minimal example :

try :
    import Tkinter as tk
except ImportError as e:
    import tkinter as tk

root = tk.Tk()
val = tk.IntVar(root)
val.trace("w", lambda a, b, c: val.set(0))
button = tk.Checkbutton(root, text="button", variable=val)
button.pack()

root.mainloop()

To reproduce :

  • launch the application

  • click on the button but keep your mouse on it (the button will change its appearance to selected)

  • leave the button's area (the button finally changes its appearance to unselected)

Why does it wait for the mouse to leave its area ? How could I force the button's appearance to change instantly ?

Thanks




Aucun commentaire:

Enregistrer un commentaire