event

Summary

A Tk command

Synopsis

event add <<virtual>> sequence ?sequence ...?
event delete <<virtual>> ?sequence sequence ...?
event generate window event ?option value option value ...?
event info ?<<virtual>>?

Documentation

man page

See Also

Examples

Alt-F4 (Windows)

event generate . <Alt-F4> ;# sudden death, somehow like [exit]

However, other Alt-(initial) events don't work when called from event, only from the keyboard.


MG: A small proc I wrote for something. It takes two arguments, a window and a keysym , and returns a two-element list. Assuming that some action is defined for the window, the first element is what the binding is to, and the second is the command actually run. If someone wants to clean my explanation up a little after looking at the proc, please go ahead, it's not particularly coherent :)

proc eventchk {w s} {
  set ret [list "" ""] ; set list [list "" ""]
  set tags [bindtags $w]
  while { $ret == $list && $tags != "" } {
          if { [bind [lindex $tags 0] $s] != "" } {
               set ret [list [lindex $tags 0] [bind [lindex $tags 0] $s]]
             } else {
               set tags [lrange $tags 1 end]
             }
        }
  return $ret;
}

text .t
eventchk .t <Return>
Text {
  tk::TextInsert %W \n
  if {[%W cget -autoseparators]} {%W edit separator}
}
bind .t <Return> {puts "You pressed return" ; break}
eventchk .t <Return>
.t {puts "You pressed return" ; break"}

MG 2005-08-02: One small "bug" - if a keysym is bound to an event (ie, <Control-c> -> <<Copy>>), searching for <Control-c> won't find it. (Searching for <<Copy>> will, but since the point of this is to find where and why a binding fires, that's not too helpful.) I'm not sure of a way around that, apart from checking [bind $window] for all events, and checking all of those to see if they fire on the binding, though...

Misc

Harold Macmillan (former UK prime minister, when asked what might most easily steer a government off course):

Events, dear boy, events.