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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with mainloop() in Tk

Status
Not open for further replies.

kokon

Programmer
Apr 27, 2006
31
PL
Hello, I need to start subroutine before MainLoop() (its a while loop) This is the sub:
--------
sub CheckTime {
$exeTime=18;
$Hour=shift(@_);
$loopStop=0;
while ($loopStop==0) {
sleep(1); # 1 = 1s
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$ZWIDGETS{'Text1'} -> insert('end',"Waiting......\n");

if ($hour==$exeTime) { $loopStop=1; $ZWIDGETS{'Text1'} -> insert('end',"Starting.....\n");}
}
return $hour;
}
----------------------------------------
And when I put it in this way, first program do the while loop and than start window:
-----------------------------------------
&CheckTime($HourGet);
MainLoop();
----------------------------------------
I need the subroutine works all the time and update Tk Text box...
Is there sth in perl like onForm_load???

I have try use the threads but Tk and threads works really bad.


Thx for help..
 
Hi man

Try this example, "configure" and "update" could help.



use Tk;
$info = "start";
$mw = MainWindow->new;
$i = 0;
$b = $mw->Button(-text=> $info)->pack();
$b->configure (-command => \&push_button);

MainLoop;


sub push_button
{
$i = 0;
while ($i < 1000000){$i++}
$b->configure(-text=>"first stage");
$b->update;
$i = 0;
while ($i <10000000){$i++}
$b->configure(-text=>"second stage");
$b->update;
$i=0;
while ($i <1000000){$i++}
$b->configure(-text=>"third stage");
$b->update;
}
[sub\]

dmazzini
GSM System and Telecomm Consultant

 
I am sorry, I messed up with the tags before..Now, more easy to read...

Code:
use Tk;
$info = "start";
$mw = MainWindow->new;
$i = 0;
$b = $mw->Button(-text=> $info)->pack();
$b->configure (-command => \&push_button);

MainLoop;


sub push_button
{
$i = 0;
while ($i < 1000000){$i++}
$b->configure(-text=>"first stage");
$b->update;
$i = 0;
while ($i <10000000){$i++}
$b->configure(-text=>"second stage");
$b->update;
$i=0;
while ($i <1000000){$i++}
$b->configure(-text=>"third stage");
$b->update;
}



dmazzini
GSM System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top