bindtags(3pm)
π bindtags(3pm) β bestie edition β¨
okay so this is Tk::bindtags, from the User Contributed Perl Documentation section of the manual, and it's literally about figuring out which bindings apply to a window and in what order they get evaluated. iykyk π
β¨ NAME β¨
Tk::bindtags β determine which bindings apply to a window, and the order of evaluation π¦
πΈ SYNOPSIS πΈ
$widget->bindtags([tagList]);
@tags = $widget->bindtags;
π DESCRIPTION π
So when you make a binding with the bind command, it gets attached to <em>something</em>. That something could be:
- a specific window, like
$widget - a class name, like
Tk::Button - the magic keyword
all - or honestly just... any other string you want
All of these are what we call binding tags. periodt.
Every window has a whole list of binding tags, and that list is what decides how events get processed for that window. When an event happens in a window, it gets applied to each of the window's tags in order β and for each tag, the most specific binding that matches both the tag and the event is the one that runs. Want the full tea on how that matching process works? Go read Tk::bind. π«Ά
By default, every window has four binding tags, and they are:
- the window's class name
- the name of the window
- the name of the window's nearest toplevel ancestor
all
...in that exact order. β¨
Toplevel windows only get three tags by default, because for a toplevel, the toplevel name is the same as the window's own name. no dupe needed π
β οΈ okay important heads up bestie: this order is different from the order Tcl/Tk uses. Tcl/Tk puts the window <em>ahead</em> of the class name in the binding order. why? because Tcl is procedural, not object oriented, so the normal way Tcl/Tk apps override class bindings is with an <em>instance</em> binding. but with perl/Tk, the normal way to override a class binding is to <em>derive a class</em>. the perl/Tk order makes instance bindings run <em>after</em> the class binding, which means instance bind callbacks can actually make use of state changes (like changes to the selection, for example) that the class bindings already made. slay. π₯
The bindtags command is your girl for reading <em>and</em> modifying a window's binding tags. π
- If you call
$widget->bindtagswith <strong>no argument</strong>, you get the current set of binding tags for$widgetback as a list. π - If you <em>do</em> pass the <em>tagList</em> argument, it has to be a <strong>reference to an array</strong> β and the tags for
$widgetget changed to the elements of that array. (you can make a reference to an anonymous array by wrapping the elements in[ ], iconic behavior honestly)
The elements of <em>tagList</em> can be arbitrary strings or widget objects. and here's the thing β if no window exists for an object at the time an event gets processed, then that tag is just <em>ignored</em> for that event. π
The order of the elements in <em>tagList</em> is what determines the order in which binding callbacks get executed in response to events. for example:
$b->bindtags([$b,ref($b),$b->toplevel,'all'])
that applies the Tcl/Tk binding order, which means binding callbacks get evaluated for a button (say) $b so that:
$b's instance bindings get invoked first- followed by bindings for
$b's class - followed by bindings for
$b's toplevel - followed by
allbindings
and if <em>tagList</em> is an <strong>empty list</strong>, i.e. [], then the binding tags for $widget get returned to the perl/Tk default state described up above. reset button, we love her π
You can also use the bindtags command to introduce arbitrary <em>additional</em> binding tags for a window, or to <em>remove</em> standard tags. for example:
$b->bindtags(['TrickyButton',$b->toplevel,'all'])
that replaces the (say) Tk::Button tag for $b with TrickyButton. which means the default widget bindings for buttons β the ones associated with the Tk::Button tag β will no longer apply to $b, but any bindings associated with TrickyButton (maybe some new button behavior you cooked up π) <em>will</em> apply. main character energy honestly.
π BUGS π
ngl, the current mapping of the 'native' Tk behaviour of this method is <em>counter intuitive</em> β like, it returns a list but only accepts a reference to an array?? make it make sense. π
The perl/Tk interface may get tidied up at some point. returning a list is sensible, so most likely the fix will be to allow a list to be passed in to set the bindtags. we'll see bestie. π€·βοΈ
π¦ SEE ALSO π¦
Tk::bind Tk::callbacks
β KEYWORDS β
binding, event, tag
okay that's the whole page, you ate that π
this was perl v5.40.1, dated 2025-04-13, and it's filed under bindtags(3pm). go forth and bind responsibly bestie πβ¨π«Ά
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms