[Tkinter-discuss] Button event calls Leave/Enter

Michael Lange klappnase at web.de
Tue May 14 12:26:37 EDT 2019


Hi,

On Tue, 14 May 2019 13:53:54 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:

> Thanks all for your replies.
> I've saw that there is a difference in the event.state, but I cannot
> find any information on what each bit represents.
>

I modified your leave() callback using the values given at:
https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-handlers.html
into:

def leave(event):
    s = event.state
    b1 = (s & 0x0100) != 0
    if b1:
        print('leave event with Button 1 pressed', 'event.state:', s)
    else:
        print('regular leave event', 'event.state:', s)

which actually seems to do the trick (btw., same behavior here with xfce,
so the exact Tk version apparently doesn't matter).
However, there still seems to be no way to tell if it is an actual Leave
event (i.e. mouse pointer dragged out of the window) while Button1 is
pressed or one of those fake-Xfce-Leave events.
The same "fake" events occur here also with Button2 and Button3, so there
might be more event.state values to consider.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

On my planet, to rest is to rest -- to cease using energy.  To me, it
is quite illogical to run up and down on green grass, using energy,
instead of saving it.
		-- Spock, "Shore Leave", stardate 3025.2


More information about the Tkinter-discuss mailing list