mastermagrath
Technical User
Hi,
Wonder can anyone give me some help.
I've written a few scripts with tk and threads and everything has been fairly straightforward until i hit this little problem. Basically i have a small GUI consisting of a Label widget. The text variable in this widget points to a shared variable. I start a new thread which periodically changes this shared variable. The problem is even though the variable is getting updated, the label widget doesn't update its text!? I know the label at least reads the shared variable on start up as it takes the initial value and i know that the variable is updated as i print out the value to STDOUT.
I've included a snippet of the program (assume all necessary modules used)
my $rate : shared = 0;
my $mw = MainWindow->new;
$mw->title('test');
my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove')->pack;
my $f1LabelBytesPerSec = $f1->Label(-textvariable => \$rate, -width => 15)->pack;
my $f1ButtonStart = $f1->Button(-text => 'Start', -command => \&Start)->pack(-side => 'left');
MainLoop;
sub Start {
my $thr = threads->new(\&Update);
}
sub Update{
while(1) {
$rate += 1;
sleep 5;
}
}
I'd really appreciate any comments as it seems like such a basic thing programmers would do when writing GUI's and using threads.
Wonder can anyone give me some help.
I've written a few scripts with tk and threads and everything has been fairly straightforward until i hit this little problem. Basically i have a small GUI consisting of a Label widget. The text variable in this widget points to a shared variable. I start a new thread which periodically changes this shared variable. The problem is even though the variable is getting updated, the label widget doesn't update its text!? I know the label at least reads the shared variable on start up as it takes the initial value and i know that the variable is updated as i print out the value to STDOUT.
I've included a snippet of the program (assume all necessary modules used)
my $rate : shared = 0;
my $mw = MainWindow->new;
$mw->title('test');
my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove')->pack;
my $f1LabelBytesPerSec = $f1->Label(-textvariable => \$rate, -width => 15)->pack;
my $f1ButtonStart = $f1->Button(-text => 'Start', -command => \&Start)->pack(-side => 'left');
MainLoop;
sub Start {
my $thr = threads->new(\&Update);
}
sub Update{
while(1) {
$rate += 1;
sleep 5;
}
}
I'd really appreciate any comments as it seems like such a basic thing programmers would do when writing GUI's and using threads.