Updated 2011-01-16 07:35:46 by RLE

[Reference to list of recognized events] [Is the bind page the best ref?] [surely there's better than [1] ]

Introduction to Events

The bind manpage lists these (standard) event types, but what do they all actually represent?
 Activate                Enter                Map
 ButtonPress, Button     Expose               Motion
 ButtonRelease           FocusIn              MouseWheel
 Circulate               FocusOut             Property
 Colormap                Gravity              Reparent
 Configure               KeyPress, Key        Unmap
 Deactivate              KeyRelease           Visibility
 Destroy                 Leave

First, the easy ones.

Mouse-Related Events

ButtonPress (which has the alias Button) should be pretty self-explanatory, as should ButtonRelease. The other events to do with the mouse are Motion and MouseWheel, again easy to understand (though things can get a bit complex with mouse-wheel handling which is mapped to high-numbered buttons on some platforms instead of using a real Z-axis.) However, there are another two mouse-related events: Enter (which is generated when the mouse goes into a widget) and Leave (which is, you've guessed it, generated when the mouse goes out.)

Key-Related Events

Obviously there's KeyPress (a.k.a. Key) and KeyRelease. However there are two other major key-related events: FocusIn and FocusOut. These deal with things relating to the movement of the keyboard focus, and are quite a bit trickier to use than you might think because of issues relating to where the focus enters and leaves a group of windows, and can get downright complex on some platforms which do a lot more focus fiddling than you might think (speaking with hard-won experience about CDE on Solaris here.)

Activation Events

Macintoshes have extra events (Activate and Deactivate) to cope with their idea of what an active window is. Nobody else uses them.

Other Basic Events

There are a few others that are often useful: Configure is delivered to the window whenever it changes position or size. Destroy is delivered after the window is deleted, to give you a chance to delete any data you've got associated with the window. Map and Unmap form a pair, the first being delivered when a window becomes potentially visible (though it might actually be obscured at this point) and the second being delivered when a window definitely becomes not potentially visible (through being withdrawn or the geometry manager being told to forget about it.)

Rare Events

Circulate delivers notifications relating to when the stacking order of windows alters, but is not supported on all platforms (particularly not on Windows.) Visibility events tell you about when a window becomes hidden by others or revealed again (which obviously has nothing to do with the stacking order) and like Circulate, it is not delivered on all platforms (particularly not Windows.)

Expose events are delivered everywhere (they indicate where a window needs to be redrawn) and are, in fact, just about the most common events of all. But Tk already handles all that sort of thing for you.

The other four events on the list are Colormap (where the configuration of the color subsystem changes; not much use these days on modern displays, and probably handled by Tk as much as needed at this point anyway), Gravity (where how a window is attached to its parent is modified; I've never seen it used because we have proper geometry managers!), Property (another one only useful on X; Tk already handles some of this for you and the rest is not currently practicable though there is a TIP on improving this support), and Reparent (where a window changes what its parent window is, which is not something that Tk supports in a deeply meaningful way other than for toplevels, where it is part of the way window managers work on X.)

There are other events about that Tk doesn't expose through the bind mechanism. You can find out more about their effects through the wm, clipboard and selection commands.

Donal Fellows

[various references, explanation, event detail fields]

"virtual event"

There are issues with Windows' respect for <Visibility> and <Circulate>.

 (bin) 2 % puts $tcl_platform(platform)
 (bin) 3 % info patchlevel
 (bin) 4 % wm withdraw .
 (bin) 5 % bind . <Visibility> {puts "visible"}
 (bin) 6 % wm deiconify .