There are many ways around this problem. First never use sleep in a gui app, unless it's in a thread. Second, put your url_fetching operations into threads or fork them off. You can try to manually pump the loop by liberally sprinkingly DoOneEvent(); in areas where the code is in a delay loop( like your in while( $fh ). Finally, use Tk::fileevent to read your filehandles, instead of a while loop. Use timers when needing delays, like Tk::repeat.#!/usr/bin/perl use Tk; my $mw = MainWindow->new; $mw->geometry('100x100+100+100'); #$mw->overrideredirect(1); my @color = qw/red green/; my $bits = pack("b8"x8, "...11...", "..1111..", ".111111.", "11111111", "11111111", ".111111.", "..1111..", "...11...",); $mw->DefineBitmap('indicator' => 8,8, $bits); my $label = $mw->Label( -bitmap=>'indicator', -bg=>'black', -fg=>'red', )->pack; $mw->repeat(500,sub{$label->configure( -fg=>$color[0]); @color=reverse(@color); }); # put in simulated eventloop blocker after 2.5 seconds # to freeze tk for 5 seconds $mw->after(2500,sub{ sleep (5) }); MainLoop;
There are many examples out there on google for using Tk with threads and shared variables. See Tk events by Lidie and a few examples of using threads and fileno's with Tk ztk-BBC-World-News-Rss-TickerTape and Re^3: Passing globs between threads
In reply to Re^3: Perl Tk freezes when command button is clicked !
by zentara
in thread Perl Tk freezes when command button is clicked !
by muralidharan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |