So I've got this simple demo for my problem:
from functools import partial
import tkinter as tk
root = tk.Tk()
root.title("Test")
root.geometry("400x400")
colors = ["red", "green", "blue"]
for x in range(3):
firstFrame = tk.Frame(root, bg=colors[x])
firstFrame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
firstFrame.bind("<Enter>", lambda e: print(f"Enter: {x}"))
firstFrame.bind("<Leave>", lambda e: partial(print, f"Leave: {x}")())
root.mainloop()
When I run the code and hover over the red section, then the green one and finally over the blue one before closing the window, I get this output:
Enter: 2
Leave: 2
Enter: 2
Leave: 2
Enter: 2
Leave: 2
What I need is:
Enter: 0
Leave: 0
Enter: 1
Leave: 1
Enter: 2
Leave: 2
As you can see I've tried multiple approaches to get the desired output, like using partial
to create a whole new function instead of simply calling print
, but nothing yielded any results.