in reply to Re: Re: Passing arguments to callback routines with named references
in thread Passing arguments to callback routines with named references
The "-command" option on Tk widgets (like the "bind" method) can accept an array ref (anonymous in this case), in which the first element of the array is the subroutine reference, and the remaining elements are args to pass to the sub.my $change_mode = \&change_mode; ... # Case 2: Callback routine called with argument (corrected): # given that $change_mode is a ref to a sub $main->Button(-text => 'To Upper Case', -command => [ $change_mode, 2 ] )->pack;
The "bind" case is a little different, because the sub will actually get the widget handle that invoked it as the first arg every time a "bound" event triggers the sub, whereas the "-command" option does not pass the widget handle as the first arg.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Passing arguments to callback routines with named references
by bobn (Chaplain) on Jul 15, 2003 at 05:19 UTC |