Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

first time using threads

0 views
Skip to first unread message

Larry

unread,
Nov 22, 2009, 6:52:12 PM11/22/09
to
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

Ben Morrow

unread,
Nov 22, 2009, 7:44:52 PM11/22/09
to

Quoth "Larry" <dontme...@got.it>:

>
> 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:

(I haven't looked at the code.) Do you know Tkx is thread-safe? Tk (that
is, Tk.pm, the old Nick Ing-Simmons perl/tk interface) is known not to
work with threads.

Ben

0 new messages