ActivePerl Documentation
|
NAMETk::callbacks - Specifying code for Tk to call.
SUPPORTED PLATFORMS
SYNOPSISOne can specify a callback in one of the following ways: Without arguments:
... => \&subname, ...
... => sub { ... }, ...
... => 'methodname', ...
or with arguments:
... => [ \&subname ?, args ...? ], ...
... => [ sub { ... } ?, args...? ], ...
... => [ 'methodname' ?, args...?], ...
DESCRIPTIONPerl/Tk has a callback, where Tcl/Tk has a command string (i.e. a fragment of Tcl to be executed). A perl/Tk callback can take one of the following basic forms:
Any of these can be provided with arguments by enclosing them and the arguments in []. Here are some examples: $mw->bind($class, ``<Delete>'' => 'Delete'); This will call $widget->Delete, the $widget being provided (by bind) as the one where the Delete key was pressed. While having bind provide a widget object for you is ideal in many cases it can be irritating in others. Using the list form this behaviour can be modified: $a->bind(``<Delete>'',[$b => 'Delete']); because the first element $b is an object bind will call $b->Delete. Note that method/object ordering only matters for $w->configure(-yscrollcommand => [ set => $ysb]); $w->configure(-yscrollcommand => [ $ysb => 'set' ]); but both will call Another use of arguments allows you to write generalized methods which are easier to re-use: $a->bind(``<Next>'',['Next','Page']); $a->bind(``<Down>'',['Next','Line']); This will call Note that the contents of the
EXAMPLES
$entry->bind('<Return>' => [$w , 'validate', Ev(['get'])]);
$toplevel->bind('all', '<Visibility>', [\&unobscure, Ev('s')]);
$mw->bind($class, '<Down>', ['SetCursor', Ev('UpDownLine',1)]);
SEE ALSOTk::bind Tk::after Tk::options Tk::fileevent
KEYWORDScallback, closure, anonymous subroutine, bind
|