Gnocl Cookbook‎ > ‎

Automating the Creation of Widget Callback Proceedure Names

Complex UI layouts often need all manner of callback handlers. Its understandable then that it might need necessary to create handlers for each widget rather than a general, type-based callback. Coming up with all manner of proc names is not only frustrating it can lead to confusion. Its much better to let the Tcl interpreter create a proc on the fly based upon the calling widget id as show in this example:

set ent(1)  [gnocl::entry \
   -data HIDIHI \
   -onActivate { %w:callBack %w %d %t } \
   -baseColor #F8F897 \
   -baseFont { Sans 9 } ]
proc $ent(1):callBack { args } { puts >>$args }

gnocl::window -child $ent(1)