event generate
Sends one event to a widget at once, and runs its bindings.
event generate WINDOW EVENT ?OPTION VALUE ...?
Description
EVENT is one event of bind, such as <Button-1>, <Key-a>, or <<Save>>, with no Double, Triple, or Quadruple. The options give the fields of the event, which the % fields of a binding show. A key event goes to the focus widget, as a key of the keyboard does. The bindings run before event generate returns.
Options
| Option | Type | Default | Description |
|---|---|---|---|
-button | integer | the button of EVENT | The button number of a button event, for %b. |
-data | string | empty | The data of a virtual event, for %d. |
-delta | number | 0 | The distance of a MouseWheel event, for %D. |
-height | integer | 0 | The height of a Configure event, for %h. |
-keycode | integer | 0 | The key code of a key event, for %k. |
-keysym | key name | the key of EVENT | The key name of a key event, for %K. |
-rootx | integer | 0 | The x position on the screen, for %X. |
-rooty | integer | 0 | The y position on the screen, for %Y. |
-state | integer | the modifiers of EVENT | The state of the modifiers and the buttons, for %s. |
-time | integer | 0 | The time of the event in milliseconds, for %t. |
-when | string | now | When the event goes to the widget. |
-width | integer | 0 | The width of a Configure event, for %w. |
-x | integer | 0 | The x position of the pointer in the widget, for %x. |
-y | integer | 0 | The y position of the pointer in the widget, for %y. |
-button N
The button number of a button event, for %b.
Sets the button of a <ButtonPress> or <ButtonRelease> event with no button in EVENT.
% bind .gf <ButtonPress> {set ::btn %b}
> event generate .gf <ButtonPress> -button 3
> set btn
3% event generate .gf <1> -button x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-data TEXT
The data of a virtual event, for %d.
Any string. A binding of the virtual event gets it in %d.
% bind .gf <<Saved>> {set ::file %d}
> event generate .gf <<Saved>> -data report.txt
> set file
report.txtEach string is valid data.
-delta NUMBER
The distance of a MouseWheel event, for %D.
A positive value is a turn away from the user. ztk accepts a fraction for a precise touchpad.
% bind .gf <MouseWheel> {set ::d %D}
> event generate .gf <MouseWheel> -delta 120
> set d
120% event generate .gf <MouseWheel> -delta x
expected integer but got "x"
-errorcode NONE-height N
The height of a Configure event, for %h.
Sets the field of the event. The widget keeps its size.
% bind .gf <Configure> {set ::cf %wx%h}
> event generate .gf <Configure> -width 77 -height 5
> set cf
77x5% event generate .gf <Configure> -height x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-keycode N
The key code of a key event, for %k.
A number of the platform for the physical key.
% bind .gf <KeyPress> {set ::code %k}
> focus .gf
> event generate .gf <KeyPress> -keycode 38
> set code
38% event generate .gf <KeyPress> -keycode x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-keysym NAME
The key name of a key event, for %K.
A key name such as Return or a. A name that ztk does not know uses the first character of NAME, or no key for an empty NAME.
% bind .gf <KeyPress> {set ::key %K}
> focus .gf
> event generate .gf <KeyPress> -keysym Return
> set key
Returnztk gives no error for a key name that it does not know.
-rootx N
The x position on the screen, for %X.
Sets the field of the event, with no effect on %x.
% bind .gf <ButtonRelease> {set ::root %X,%Y}
> event generate .gf <ButtonRelease-1> -rootx 5 -rooty 6
> set root
5,6% event generate .gf <1> -rootx x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-rooty N
The y position on the screen, for %Y.
Sets the field of the event, with no effect on %y.
% bind .gf <ButtonRelease-2> {set ::ry %Y}
> event generate .gf <ButtonRelease-2> -rooty 9
> set ry
9% event generate .gf <1> -rooty x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-state N
The state of the modifiers and the buttons, for %s.
The bits of X11: 1 is Shift, 4 is Control, 8 is Mod1, and 256 is button 1. A binding with a modifier, such as <B1-Motion>, matches an event with that bit.
% bind .gf <B1-Motion> {set ::drag %s}
> event generate .gf <Motion> -state 256
> set drag
256% event generate .gf <1> -state x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-time MS
The time of the event in milliseconds, for %t.
Sets the field of the event.
% bind .gf <ButtonRelease-3> {set ::t %t}
> event generate .gf <ButtonRelease-3> -time 99
> set t
99% event generate .gf <1> -time x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-when WHEN
When the event goes to the widget.
ztk has only now, which runs the bindings before event generate returns. head, mark, and tail of Tk give an error.
Values: now.
% event generate .gf <1> -when now% event generate .gf <1> -when tail
event generate option "-when tail" is not supported in this stage
-errorcode NONE
% event generate .gf <1> -when soon
bad -when value "soon": must be now, head, mark, or tail
-errorcode NONE-width N
The width of a Configure event, for %w.
Sets the field of the event. The widget keeps its size.
% bind .gf <Configure> {set ::cw %w}
> event generate .gf <Configure> -width 40
> list $cw [winfo width .gf]
40 20% event generate .gf <Configure> -width x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-x N
The x position of the pointer in the widget, for %x.
An integer count of pixels from the left edge of WINDOW.
% bind .gf <Motion> {set ::mx %x}
> event generate .gf <Motion> -x 7
> set mx
7% event generate .gf <1> -x a
expected integer but got "a"
-errorcode TCL VALUE NUMBER-y N
The y position of the pointer in the widget, for %y.
An integer count of pixels from the top edge of WINDOW.
% bind .gf <Motion> {set ::my %y}
> event generate .gf <Motion> -y 8
> set my
8% event generate .gf <1> -y a
expected integer but got "a"
-errorcode TCL VALUE NUMBERReturns
An empty string.
Examples
% frame .gf -width 20 -height 20
> pack .gf
> update
> bind .gf <Button-1> {set ::hit %x,%y}
> event generate .gf <Button-1> -x 3 -y 4
> set hit
3,4
Errors
% event generate .gf
wrong # args: should be "event generate window event ?-option value ...?"
-errorcode NONE
% event generate .nope <1>
bad window path name ".nope"
-errorcode NONE
% event generate .gf <1><2>
only one event specification allowed
-errorcode NONE
% event generate .gf <Double-1>
Double, Triple, or Quadruple modifier not allowed
-errorcode NONE
% event generate .gf <1> -x
value for "-x" missing
-errorcode NONE
# Each option of Tk that ztk does not have gives this error.
% event generate .gf <1> -count 1
event generate option "-count" is not supported in this stage
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1