in reply to Tk -textvariable doesn't change when Entry widget changes
When you create a PerlTk callback that will take arguments, using the [] syntax, the Tk::callbacks documentation says:
the contents of the [] are evaluated by perl when the callback is created
Therefore, your code,
is roughly the equivalent of this:$mw->Button ( -command => [\&print_entries, $user_x->get(), $original_y], );
my $command_sub; { my $x_at_time_of_sub_definition = $user_x->get(); my $y_at_time_of_sub_definition = $original_y; $command_sub = sub { print_entries( $x_at_time_of_sub_definition, $y_at_time_of_sub_definition, ); } } $mw->Button ( -command => $command_sub, );
Instead of telling PerlTk to create the callback, create it yourself with an anonymous sub. This should work for you:
-command => sub { print_entries( $user_x->get(), $user_y->get(), $original_x, $original_y, ); },
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk -textvariable doesn't change when Entry widget changes
by Petras (Friar) on Sep 26, 2005 at 03:17 UTC |