Chapter 14. Binding Events

Perl/Tk is an event-driven programming language. You design your program to respond to events generated by the program. Event sequences can be pushing a button, moving the mouse, or typing some characters with a keyboard. The relationship between the event sequence and the widget is called a binding.

Each widget provided with Perl/Tk has its own default bindings. For example, the button widget changes color when the mouse pointer is over the button and it invokes a callback that you specified when it is clicked. These are default bindings, ones that are created when you create the widget itself.

You can have your program respond to additional events by using the bind command to assign callbacks to different event sequences; the basic format is:

$widget->bind(sequence, callback);

In addition, you can override the default bindings by creating your own or just removing them.

Get Learning Perl/Tk 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.