Reputation: 85
use Thread;
use warnings;
use Tk;
my $x = 10;
my $mw = new MainWindow;
$mw->Label(-text => 'honeywell')->place(-x => $x, -y => 50);
my $thr = new Thread \&sub1;
sub sub1 {
for ($i = 0 ; $i < 20 ; $i++) {
$x += 20;
sleep(2);
$mw->update;
}
}
MainLoop;
I am trying to update the label so that the text appears going down.I want to implement it using thread.But the text os not sliding down.Can anyone plz help me?
Upvotes: 0
Views: 1268
Reputation: 967
Try this code:
use strict;
use warnings;
use Tk;
my $x = 10;
my $mw = new MainWindow;
my $label = $mw->Label(-text => 'honeywell')->place(-x => $x, -y => 50);
$mw->repeat(2000, \&sub1);
sub sub1 {
return if $x >= 400;
$x += 20;
$label->place(-x => $x, -y => 50);
$mw->update;
}
MainLoop;
Upvotes: 3
Reputation: 13646
I don't think that this will ever work (using Thread
or threads
).
place
uses the content of $x
and does not bind the variable $x
. So changing the variable after the initial placement won't do anything to the label.
Upvotes: 0