Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Per/Tk - text widget does not get updated 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

I define the window :
my $mw = new MainWindow; # Main Window
my $frm_name = $mw -> Frame() -> pack();
my $lab1 = $frm_name -> Label(-text=>"Enter the remote hostname or IP:") -> pack();
my $ent1 = $frm_name -> Entry() -> pack();
my $lab2 = $frm_name -> Label(-text=>"Enter the number of iterations to run [5]:") -> pack();
my $ent2 = $frm_name -> Entry() -> pack();
my $but = $mw -> Button(-text=>"Start nettest", -command =>\&start) -> pack(); #Text Area
$txt = $mw -> Text(-width=>70, -height=>20) -> pack();

MainLoop;
###################################
Then in subroutine "start" I write tesxt:


$txt -> delete("1.0",'end');
$txt -> insert('end',"Remote Hostname:\t$REMOTE_HOST\n");
$txt -> insert('end',"Remote IP address:\t$REMADDR\n");
$txt -> insert('end',"My IP address:\t\t$MYADDRESS\n\n");
###################################
Then later in the same sub I create a file :

open(FILE,">$FILE1");
print FILE ' ' x (100 * (1024 * 1024));
close FILE;
chmod 0777 => $FILE1;

The problem is that the text widget is not updated till the file creation is over (couple of minutes).Printing to STDOUT at the same time completes immediately.
Setting "$|" to "1" did not change much,as I expected to ...

Appreciate any input.

Thanks







Long live king Moshiach !
 
Actualy,I now have found out that the text widget will not get updated at all till I "return" from the "start" subroitine...
Does it mean that while the subroitine is running,I will not be able to update the text widget ?

Long live king Moshiach !
 
Use $mw->update to update the GUI at any point you want to. Don't call it TOO rapidly though or it may take up a lot of memory. e.g.

while (1) {
$mw->update;
}

That will spike up to 100% CPU usage, whereas

while (1) {
select (undef,undef,undef,0.1); # Sleep .1 seconds
$mw->update;
}

doesn't

So add a $mw->update between the longer commands in your subroutine or whereever you want visual feedback (but call it enough so that your program's user won't think the program froze up, because that's what happens when it stops updating)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top