Skip to content

tkinter (Linux) <Enter> and <Leave> events trigger on mouse buttons #150370

@cromachina

Description

@cromachina

Bug report

Bug description:

If your mouse enters or leaves the window, the events print as expected, however if you click and even scroll in the window, the enter and leave events will fire on each invocation. This appears to be a Linux bug, as it did not seem to occur in a Windows 10 virtual machine.

import tkinter as tk
import time
def print_event(e):
    print(time.time(), e)
app = tk.Tk()
app.geometry('800x600')
app.bind('<Enter>', print_event)
app.bind('<Leave>', print_event)
app.mainloop()

Example output. The events get filled with button state information, which might indicate the source of the problem (why would an enter or leave event be tracking button state?). When a button is pressed, the enter and leave events appear to fire at almost the exact same time as well.

1779680250.310537 <Enter event focus=True x=643 y=2>
1779680251.4646537 <Leave event state=Button1 focus=True x=361 y=214>
1779680251.4704258 <Enter event state=Button1 focus=True x=361 y=214>
1779680253.1646419 <Leave event state=Button1 focus=True x=361 y=214>
1779680253.170706 <Enter event state=Button1 focus=True x=361 y=214>
1779680256.994624 <Leave event state=Button3 focus=True x=361 y=214>
1779680257.0038812 <Enter event state=Button3 focus=True x=361 y=214>
1779680259.502435 <Leave event focus=True x=272 y=603>

System Info:

OS: NixOS 26.05
Kernel: Linux 7.0.3-zen1
Desktop environment: Xfce 4.20.0
Window system: X11 (X.Org 21.1.22)

VM Info:

OS: Windows 10

CPython versions tested on:

3.14, 3.13

Operating systems tested on:

Linux, Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-linuxpendingThe issue will be closed if no feedback is providedtopic-tkintertype-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions