Tkinter Leave event firing only on program startup?

165 Views Asked by At

I'm trying to place a small label hinting the user the keyboard shortcut bound to it, which works fine.

enter image description here

The problem arises when I'm leaving the button. The label disappears, but not quite. If I try to click the button in the area the label "used" to be, it won't fire, indicating that's it's somehow still there. So I thought maybe buttons have a Leave event already built in that raises them to the top level. I decided to try and override that, and basically tell the button go (or better yet, just stay) below the key-hint label hit_button.bind("<Leave>", hit_button.lower(hit_button_keyhint), to no avail. What am I doing wrong?

                                       fg=hit_button['fg'])
    hit_button_keyhint.place(relx=0.5, rely=0.85, anchor='center')
    hit_button.bind("<Leave>", hit_button.lower(hit_button_keyhint))
1

There are 1 best solutions below

0
On

You need to pass a function to the binding, Here you execute a function. (hit_button.lower(hit_button_keyhint))

To do so, you should use a lambda.

You can get some clarifications here: Tkinter binding a function with arguments to a widget

But this should work:

hit_button.bind("<Leave>",lambda event, k=hit_button_keyhint:hit_button.lower(k)