3

I would like to improve my program, I just do not know how.

I want that an event starts, when the users mouse is over a tkinter's widget.

This...

button.bind("<Motion>", lambda eff: callback())

... is working, but the users needs to move the mouse for call the function.

Is there a way to start, for example, every x seconds the function while the mouse is over the widget?

I need it to display an integer that changes constantly as text of a button or a label while the mouse is over the button or label.

Do you have any Ideas?

Thanks for your attention,

Lukas

Lukas
  • 446
  • 3
  • 11

1 Answers1

4

You can bind a function to <Enter> to trigger a function when the mouse enters a widget, and you can bind to <Leave> to trigger when it leaves.

The <Enter> binding can run a function that starts updating the label periodically using after. The <Leave> binding can set a flag that the update function checks in order to know to stop updating.

There are many questions and answers on this site about using after to do something periodically. For example, How to use the after method to make a callback run periodically?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685