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,

$mw->Button ( -command => [\&print_entries, $user_x->get(), $original_y], );
is roughly the equivalent of this:
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
    For reasons in the *real* application I need to create a call back to a real sub. Thank you, though for your insight on when variables are evaluated in brackets and sub calls.

    Cheers!
    --P


    Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.

    -Howard Aiken