http://www.perlmonks.org?node_id=790448

smithbr has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am just starting with Tk and I'll admit, I don't get a chance to write a lot of Perl. But, this seems very simple to me so I can't figure out why it won't work.

#!/usr/bin/perl -w use Tk; use strict; my $text = "foo"; my $mw = MainWindow->new; my $button = $mw->Button(-text=>'Change entry', -command=>\&change)->p +ack(); my $entry = $mw->Entry(-textvariable=>$text)->pack(); MainLoop; sub change { print "\$text before: $text\n"; $text = "bar"; print "\$text after: $text\n"; $mw->update; }

I assume I must be doing something really stupid because my entry never gets updated, but $text changes from the prints.

If I add $entry->configure(-textvariable=>$text) before the $mw->update() it works ok. However, all the documentation suggests if I use textvariable, changing the variable anywhere should magically update the widget text.

I searched around, but the similar problems I saw were much more complicated than this so I didn't get a lot of help from them.

Thanks.