in reply to Re: displaying program status in perl tk
in thread displaying program status in perl tk

Hi jethro,
Thanks for the quick response. With the modified code, I have to click the button each time to make the status message change. Isn't there some way of making the script update the mainloop from within a while loop as and when the status message changes?
  • Comment on Re^2: displaying program status in perl tk

Replies are listed 'Best First'.
Re^3: displaying program status in perl tk
by robobunny (Friar) on Feb 04, 2009 at 16:59 UTC
    You can keep a reference to the label and update it directly. This is generally how you have to handle any progress/meter type stuff that needs to be updated in a loop. (This is untested but should be pretty close)
    my $counter_label = $mw->Label(-text => $no, -relief => 'sunken', -anchor => 'center') ->place(-relx =>0.0, -rely => 0.80, -relwidth => 1.0, -relheight = +> 0.2); ... sub count { if ($upper_no > 0) { $no = 0; while ($no < $upper_no) { $no++; $counter_label->configure(-text => $no); } } }
Re^3: displaying program status in perl tk
by boblawblah (Scribe) on Feb 04, 2009 at 22:00 UTC
    Putting this code in your loop should do the trick. I haven't tested it.
    while(1) { last unless DoOneEvent($TK_DONT_WAIT); }
    DoOneEvent is the routine called from MainLoop.

    When passed the exported variable $TK_DONT_WAIT it returns true if there was an event to process, and false if otherwise. So DoOneEvent will continue to be called until there are no more events pending (and the only event pending would be the updating of your status bar). Then your program would continue on where it left off.

    Read more about the main loop here.