http://qs1969.pair.com?node_id=477030


in reply to Updating Tk window in real time

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"); }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.