L
Larry
Hi,
I'm stuck at thread as I've just starting using it. I would like to
spawn (and detach) a thread which update a text label in a Tk window. The
following is the code:
#!/wperl
use strict;
use warnings;
use Tkx;
use threads;
use threads::shared;
my $k : shared = 0;
my $mw = Tkx::widget->new(".");
$mw->g_wm_title('Hello World!');
$mw->g_wm_geometry("400x250-5+5");
my $mf = $mw->new_ttk__frame();
$mf->g_grid();
my $la = $mf->new_ttk__label(-textvariable => \$k);
$la->g_grid();
my $thr = threads->new(\&_sub1);
$thr->detach();
Tkx::MainLoop();
sub _sub1 {
while(1)
{
$k = $k + 1; sleep 1;
}
}
__END__;
I thought the text label would be updated every 1 second. Yet, it gets the
firts update then it does not anymore...what am I doing wrong?
thanks
I'm stuck at thread as I've just starting using it. I would like to
spawn (and detach) a thread which update a text label in a Tk window. The
following is the code:
#!/wperl
use strict;
use warnings;
use Tkx;
use threads;
use threads::shared;
my $k : shared = 0;
my $mw = Tkx::widget->new(".");
$mw->g_wm_title('Hello World!');
$mw->g_wm_geometry("400x250-5+5");
my $mf = $mw->new_ttk__frame();
$mf->g_grid();
my $la = $mf->new_ttk__label(-textvariable => \$k);
$la->g_grid();
my $thr = threads->new(\&_sub1);
$thr->detach();
Tkx::MainLoop();
sub _sub1 {
while(1)
{
$k = $k + 1; sleep 1;
}
}
__END__;
I thought the text label would be updated every 1 second. Yet, it gets the
firts update then it does not anymore...what am I doing wrong?
thanks