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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.