1bindtags(3) User Contributed Perl Documentation bindtags(3)
2
3
4
6 Tk::bindtags - Determine which bindings apply to a window, and order of
7 evaluation
8
10 $widget->bindtags([tagList]);
11
12 @tags = $widget->bindtags;
13
15 When a binding is created with the bind command, it is associated
16 either with a particular window such as $widget, a class name such as
17 Tk::Button, the keyword all, or any other string. All of these forms
18 are called binding tags. Each window has a list of binding tags that
19 determine how events are processed for the window. When an event
20 occurs in a window, it is applied to each of the window's tags in
21 order: for each tag, the most specific binding that matches the given
22 tag and event is executed. See the Tk::bind documentation for more
23 information on the matching process.
24
25 By default, each window has four binding tags consisting of the the
26 window's class name, name of the window, the name of the window's
27 nearest toplevel ancestor, and all, in that order. Toplevel windows
28 have only three tags by default, since the toplevel name is the same as
29 that of the window.
30
31 Note that this order is different from order used by Tcl/Tk. Tcl/Tk
32 has the window ahead of the class name in the binding order. This is
33 because Tcl is procedural rather than object oriented and the normal
34 way for Tcl/Tk applications to override class bindings is with an
35 instance binding. However, with perl/Tk the normal way to override a
36 class binding is to derive a class. The perl/Tk order causes instance
37 bindings to execute after the class binding, and so instance bind
38 callbacks can make use of state changes (e.g. changes to the selection)
39 than the class bindings have made.
40
41 The bindtags command allows the binding tags for a window to be read
42 and modified.
43
44 If $widget->bindtags is invoked without an argument, then the current
45 set of binding tags for $widget is returned as a list. If the tagList
46 argument is specified to bindtags, then it must be a reference to and
47 array; the tags for $widget are changed to the elements of the array.
48 (A reference to an anonymous array can be created by enclosin the
49 elements in [ ].) The elements of tagList may be arbitrary strings or
50 widget objects, if no window exists for an object at the time an event
51 is processed, then the tag is ignored for that event. The order of the
52 elements in tagList determines the order in which binding callbacks are
53 executed in response to events. For example, the command
54
55 $b->bindtags([$b,ref($b),$b->toplevel,'all'])
56
57 applies the Tcl/Tk binding order which binding callbacks will be
58 evaluated for a button (say) $b so that $b's instance bindings are
59 invoked first, following by bindings for $b's class, followed by
60 bindings for $b's toplevel, followed by 'all' bindings.
61
62 If tagList is an empty list i.e. [], then the binding tags for $widget
63 are returned to the perl/Tk default state described above.
64
65 The bindtags command may be used to introduce arbitrary additional
66 binding tags for a window, or to remove standard tags. For example,
67 the command
68
69 $b->bindtags(['TrickyButton',$b->toplevel,'all'])
70
71 replaces the (say) Tk::Button tag for $b with TrickyButton. This means
72 that the default widget bindings for buttons, which are associated with
73 the Tk::Button tag, will no longer apply to $b, but any bindings
74 associated with TrickyButton (perhaps some new button behavior) will
75 apply.
76
78 The current mapping of the 'native' Tk behaviour of this method i.e.
79 returning a list but only accepting a reference to an array is counter
80 intuitive. The perl/Tk interface may be tidied up, returning a list is
81 sensible so, most likely fix will be to allow a list to be passed to
82 set the bindtags.
83
85 Tk::bind Tk::callbacks
86
88 binding, event, tag
89
90
91
92perl v5.28.0 2018-07-15 bindtags(3)