widget - Tcl/Tk: how to trigger bind function inside script instead of GUI operation -


in tcl/tk script, there combobox widget, , bind event it, if user change selection of combobox, bind function triggered.
want trigger bind function inside script, instead of gui operation, how this? code goes following:

ttk::combobox .combo_select_tag -background white; .combo_select_tag configure -value "1 2 3"; pack .combo_select_tag  bind .combo_select_tag <<comboboxselected>> {     puts "trigger\n" } 

tl;dr use event generate.


the bind command associates binding script event on binding tag. each widget typically has 4 binding tags: name of widget, name of widget's class, name of widget's toplevel, , all binding tag. (the aim put customizations on individual widgets, or on toplevel have them apply whole window — which great hotkey sequences — while tk focuses on class level. global all level not used has few backstop things.)

to activate binding script, need event sent widget. event generate command precisely that. can generate “real” events (like <buttonpress-1> or <keyrelease-comma>) or can generate “virtual” events (like <<comboboxselected>>) , in fact all virtual events generated via event generate (or c api it's thin wrapper over).

generating real event bit complicated, hold quite bit of information (e.g., location, they're talking about, area of widget invalidated, etc.) generating virtual event pretty easy: need know widget it's going , widget called.

event generate .combo_select_tag <<comboboxselected>> 

that's it. there's whole bunch of options can pass (that control things %-substitutions , how event queued) don't need of them of time, virtual events.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -