in reply to Tk -textvariable doesn't change when Entry widget changes

I believe that you need to pass a reference to a (Update: Scalar) variable into the -textvariable parameter for an entry widget.

use Tk; require Tk::Entry; require Tk::Button; my $mw = MainWindow->new(); my($var1, $var2) = ('val1', 'val2'); my $entry1 = $mw->Entry(-textvariable=> \$var1)->pack(); my $entry2 = $mw->Entry(-textvariable => $var2)->pack(); my $but = $mw->Button(-text=>'print', -command=> sub{print "$var1, $va +r2\n"; } )->pack(); MainLoop; __END__ # Output upon pressing print after changeing both entry widget's: entry1, val2

Update: Please note that I intentioally left off the backslash on $val2 to demonstrate the different behavior when passing a simple value rather than a scalar reference.


They say that time changes things, but you actually have to change them yourself.

—Andy Warhol