-1

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))
vl3005
  • 45
  • 4
  • Also, I forgot to mention, using `print("left")` I realized the event only triggered once on the game startup, but never again. Why would it trigger before I even entered the button with the cursor? – vl3005 Oct 07 '20 at 05:53
  • Please [edit] your question to include a [mcve]. – Bryan Oakley Oct 07 '20 at 14:02

1 Answers1

0

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)
Jean-Marc Volle
  • 3,113
  • 1
  • 16
  • 20