Using DoOneEvent() with DONT_WAIT inside your get() sub allows the window to be built and updated in real time. (I've simulated your module with a random sleep)
use strict; #use mship; use Tk qw[ MainLoop DoOneEvent DONT_WAIT ]; my $host; $|++; my $mainwindow = new Tk::MainWindow(); my $text = $mainwindow->Scrolled( "Text", -scrollbars => 'se' )->pack( -expand => 1 , -fill => 'both' ); for ( 0 .. 53 ) { DoOneEvent( DONT_WAIT ) for 1 .. 100; ## process pending events; get($_); } # create a closebutton my $button = $mainwindow->Button( -text => "close", -command => sub{ $mainwindow->destroy() } )->pack(); # start the main loop! MainLoop; sub get { sleep rand 3; my $remote_name = "remote: $_[ 0 ]"; my $stats= rand() > 0.5 ? "Up" : "Down"; $text->insert( 'end', "$remote_name is $stats\n"); }
My choice of for 1 .. 100; is somewhat arbitrary. It would be nice if you could say DoPendingEvents() or DoOneEvent() while EventsPending();, but I never found anything like that.
Update: Wadda ya know--seems DoPendingEvents() is called update():
use strict; #use mship; use Tk; my $host; $|++; my $mainwindow = new Tk::MainWindow(); my $text = $mainwindow->Scrolled( "Text", -scrollbars => 'se' )->pack( -expand => 1 , -fill => 'both' ); for ( 0 .. 53 ) { $mainwindow->update; get($_); } my $button = $mainwindow->Button( -text => "close", -command => sub{ $mainwindow->destroy() } )->pack(); MainLoop; sub get { sleep rand 3; my $remote_name = "remote: $_[ 0 ]"; my $stats= rand() > 0.5 ? "Up" : "Down"; $text->insert( 'end', "$remote_name is $stats\n"); }
In reply to Re: Updating Tk window in real time
by BrowserUk
in thread Updating Tk window in real time
by tcf03
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |