in reply to Tk -textvariable doesn't change when Entry widget changes
Using the array-ref style of -command is tricky and has limited usefulness, so I'll show you how to do it using an Entry with -textvariable, and using a Button -command with a real sub.
First, when using -textvariable, you want to give a reference to the variable, like so:
my $original_x = 3; my $user_x = $f1->Entry( -textvariable => \$original_x )->pack;
Then, whenever $original_x is tested/printed/etc., it contains whatever is currently in the entry box.
Here's a good way to use -command:
$mw->Button( -command => \&print_entries )->pack; sub print_entries { my $val = $user_x->cget('-text'); print "$val\n"; }
The salient facts are these:
Of course, in this simple program you showed, you don't need to do either of those things, because you already have the variable in scope:sub print_entries { my $var_ref = $user_x->cget('-textvariable'); my $val = $$var_ref; print "$val\n"; }
(assuming you've used the -textvariable option as above.)sub print_entries { print "$original_x\n"; }
|
|---|
| 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:08 UTC |