first time using threads

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top