Events

The widgets in the Tk collection do a pretty good job of handling their own events. For example, the Button widget handles a mouse click by calling the function specified by –command. The Text Entry widget handles keypress events by putting the characters typed in the entry.

But sometimes you may want to handle additional events. The bind method is used to connect an event, widget, and subroutine together. For example, suppose that you want to implement a status line in which context help is displayed when the mouse is placed over a widget.

The two events you are interested are <Enter> (mouse enters the widget’s window) and <Leave> (mouse leaves the widget). The bind calls look like the following:

 $tk_exit_button–>bind('<Enter>', sub ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.