Bloodelf has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a TK script that uses a label to display the current status. The script has a button that calls a sub similar to this:
sub update {$main->configure(-cursor=>"watch"); $textbox->configure(-text =>"Updating Something...") find(\&check_file,$path); $main->configure(-cursor=>"arrow"); $textbox->configure(-text =>"Status normal.");}
The problem is that the find command takes several seconds, and the neither the label or the cursor will update until the sub returns. This gives the user the impression that the script has frozen. Is there any way around this??
Cheers.

Replies are listed 'Best First'.
Re: Tk sub calling problem
by {NULE} (Hermit) on Dec 09, 2001 at 04:43 UTC
      If the find itself is taking several seconds then put the $main->update() in the callback subroutine (check_file?) and execute it occasionally.
      Many thanks.
      My bad, sorry for the post...
      Sparky
(ichimunki) Re: Tk sub calling problem
by ichimunki (Priest) on Dec 09, 2001 at 23:54 UTC
    In addition to updating the screen, which you can sprinkle liberally through your code if need be, you may also want to consider linking your textbox or label to a variable (a global works well in this case-- and since it's a GUI that's probably OK) rather than hardcoding the text in with configure.

    my $Status = 'Starting application'; my $label = $main->label( -textvariable => \$Status ); $Status = 'Done loading application';

    You may still have to update the window to get changes in $Status to appear, but it will make updating a status bar a lot simpler to type.