event
Defines virtual events, and sends events to widgets from a script.
event SUBCOMMAND ?ARG ...?
Description
A virtual event has a name in double angle brackets, such as <<Save>>, and one or more physical sequences. When a physical sequence occurs in a widget, a binding of the virtual event on a tag of the widget runs, as bind describes. A widget can also get a virtual event from event generate alone, with no sequence.
event generate sends an event to a widget at once, as if it came from the platform. A test drives the bindings of a widget with it, also in ztk --headless.
Subcommands
| Subcommand | Description |
|---|---|
event add | Adds physical sequences to a virtual event. |
event delete | Removes sequences from a virtual event, or removes the virtual event. |
event info | Gives the virtual events, or the sequences of one virtual event. |
event generate | Sends one event to a widget at once, and runs its bindings. |
Examples
# The key F5 is a sequence of `<<Go>>`, so the binding of `<<Go>>` runs.
% frame .f -width 20 -height 20
> pack .f
> update
> event add <<Go>> <Key-F5>
> bind .f <<Go>> {set ::go 1}
> focus .f
> event generate .f <Key-F5>
> set go
1
Errors
% event
wrong # args: should be "event option ?arg1 arg2 ...?"
-errorcode TCL WRONGARGS
% event bogus
bad option "bogus": must be add, delete, generate, or info
-errorcode NONE
Differences from Tcl
- The errors of
eventhave the-errorcodeNONE, except the errors of the count of arguments and of an integer. Tk 8.6.16 gives a code such asTK EVENT KEYSYM. - The subcommands need their full names. Tk 8.6.16 accepts a unique short form, such as
iforinfo. - ztk defines no standard virtual events, such as
<<Copy>>or<<SelectAll>>, soevent infolists only the virtual events of the script. Tk 8.6.16 defines more than 30 of them. - Some messages of a wrong count of arguments differ:
event option ?arg1 arg2 ...?,event add <<virtual>> sequence ?sequence ...?, andevent info ?<<virtual>>?. Tk 8.6.16 givesevent option ?arg?,event add virtual sequence ?sequence ...?, andevent info ?virtual?. event generatedoes not have the options-above,-borderwidth,-count,-detail,-focus,-mode,-override,-place,-root,-sendevent,-serial,-subwindow,-warp, and-window. Each one gives the errorevent generate option "OPTION" is not supported in this stage.event generate -whenhas onlynow. Tk 8.6.16 also puts the event in the queue withhead,mark, ortail.-x,-y,-rootx,-rooty,-width, and-heightofevent generateneed an integer. Tk 8.6.16 accepts a screen distance, such as1c.-deltaofevent generateaccepts a fraction. Tk 8.6.16 needs an integer.-keysymofevent generategives no error for an unknown key name. Tk 8.6.16 givesunknown keysym "NAME".
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1