I bind the enter-event to a Tkinter canvas widget. But it seems that Tkinter on Windows 11 and Tkinter on Linux Mint handle the event differently. In my example the enter-event is bound to the green canvas when the pointer moves into the red frame. So when moving the pointer out of the frame back into the canvas, the canvas enter-event should be triggered. This works with Windows 11, but on Linux Mint the canvas enter-event is only triggered when I move the pointer first inside the red frame and then outside the application window and then back into the canvas.
What is the explanation for this? How can I avoid such problems?
import tkinter as tk
func_id = None
def activate_frame():
print("entered frame")
global func_id
frame.unbind("<Enter>",func_id)
func_id = canvas.bind("<Enter>", lambda event: deactivate_frame())
def deactivate_frame():
print("entered canvas")
global func_id
canvas.unbind("<Enter>",func_id)
func_id = frame.bind("<Enter>", lambda event: activate_frame())
root = tk.Tk()
canvas = tk.Canvas(root, height=200, width=200, bg="green")
frame = tk.Frame(canvas, borderwidth=20, background="red")
text = tk.Text(frame, width=5, height=1)
canvas.grid()
# frame.grid() is not called, instead frame is put into a canvas-window:
canvas.create_window(100,100, window=frame)
text.grid()
func_id = frame.bind("<Enter>", lambda event: activate_frame())
root.mainloop()