[Tkinter-discuss] Button event calls Leave/Enter

Vasilis Vlachoudis Vasilis.Vlachoudis at cern.ch
Thu May 9 03:58:42 EDT 2019

Hi all,

I've just realized that the mouse click <Button-1> event generates as well
a <Leave> followed by <Enter> event before.
With the program below, if one clicks in the frame
you get the messages printed
Leave event
Enter event
Button1 pressed
Which I don't understand the reasoning behind. However it generates
a problem to my application since I have some actions that are binded with
the Leave event and when the button1 handler is called the program
has already altered some structures.
Is there a way forbit the calls to Leave/Enter before the Button1?

Many thanks in advance

import tkinter as tk
def enter(event): print("Enter event")
def leave(event): print("Leave event")
def button1(event): print("Button1 pressed")

root = tk.Tk()
frame = tk.Frame(root, bg="Yellow",
width=600, height=400)
frame.pack(fill=tk.BOTH, expand=tk.YES)
frame.bind("<Enter>", enter)
frame.bind("<Leave>", leave)
frame.bind("<Button-1>", button1)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20190509/b6416784/attachment.html>

More information about the Tkinter-discuss mailing list