<?xml version="1.0" encoding="windows-1252"?>
<node id="790448" title="Tk Entry not updating when textvariable changes" created="2009-08-21 15:22:40" updated="2009-08-21 15:22:40">
<type id="115">
perlquestion</type>
<author id="790443">
smithbr</author>
<data>
<field name="doctext">
&lt;p&gt;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.
&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl -w 
use Tk; 
use strict;

my $text = "foo";

my $mw = MainWindow-&gt;new; 

my $button = $mw-&gt;Button(-text=&gt;'Change entry', -command=&gt;\&amp;change)-&gt;pack();
my $entry = $mw-&gt;Entry(-textvariable=&gt;$text)-&gt;pack();

MainLoop;

sub change
{
	print "\$text before: $text\n";
	$text = "bar";
	print "\$text after: $text\n";
	$mw-&gt;update;
}
&lt;/code&gt;
&lt;p&gt;
I assume I must be doing something really stupid because my entry never gets updated, but $text changes from the prints. &lt;/p&gt;
&lt;p&gt;If I add
$entry-&gt;configure(-textvariable=&gt;$text)
before the $mw-&gt;update() it works ok. However, all the documentation suggests if I use textvariable, changing the variable anywhere should magically update the widget text.
&lt;/p&gt;
&lt;p&gt;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.&lt;/P&gt;
&lt;p&gt;
Thanks.&lt;/p&gt;</field>
</data>
</node>
