0
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?

Stamm
  • 947
  • 5
  • 17
amit
  • 85
  • 8
  • 2
    http://search.cpan.org/dist/perl/lib/Thread.pm#DEPRECATED : `You are strongly encouraged to migrate any existing threaded code to the new model (i.e., use the threads and threads::shared modules) as soon as possible.` – daxim Mar 13 '12 at 09:20

2 Answers2

3

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;
Stamm
  • 947
  • 5
  • 17
  • Thanx for the answer.Its working but i want to perform some other work in the window simultaneously with the moving label.I think i need to use thread for this.Can you please help me out? – amit Mar 14 '12 at 09:07
  • Using threads with Tk is difficult. See this discussion: [Perl Tk and Threads](http://www.perlmonks.org/?node_id=732320) – Stamm Mar 14 '12 at 13:42
0

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.

dgw
  • 13,418
  • 11
  • 56
  • 54