22. Events and Bindings

You have already seen that Tcl scripts can be associated with widgets such as buttons or menus so that the scripts are invoked when certain events occur, such as clicking a mouse button over the widget. These mechanisms are provided as specific features of specific widget classes. Tk also provides a more general mechanism called bindings, which allow you to create handlers for any event in any window. A binding “binds” a Tcl script to an event or sequence of events in one or more windows so that the script is evaluated whenever the given event sequence occurs in any of the windows. You can use bindings to extend the basic functions of a widget, for example, by defining shortcut keys for common actions. You can also override ...

Get Tcl and the Tk Toolkit, Second Edition 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.