in reply to Redraw Frame in Perl/TK

Update: Added example code

Um... would you believe:

$widget->update;

Still, I can't help feeling that there might be something you're leaving out. Perhaps if you could provide a small working example that demonstrates your problem?

The classic case that I've seen in Perl/Tk is that someone has a long running subroutine that does something and prevents the GUI from processing new events until the sub is complete. Take the following script:

use strict; use Tk; my $counter = 0; my $mw = MainWindow->new(-title => "Counter"); $mw->Label(-textvariable => \&runCounter)->pack; $mw->Button( -text => 'Start Counter', -command => \&counter )->pack; MainLoop; sub runCounter { $counter = 0; while ($counter != 100000) { $counter++; } }

In the preceding script, the window will seem to freeze once you press the "Start Counter" button, and the numbers will change to 100000 once the sub has completed. If those numbers were a progress bar, then that's not going to be acceptable. Also if you were to move a window in front of the Counter window while it's counting and then move it away, the screen will not be refreshed until the counter stops.

Now, try modifying the runCounter sub to the following and rerun the script.

sub runCounter { $counter = 0; while ($counter != 100000) { $counter++; $mw->idletasks; } }

You should now see the Label updated as the counter increases, but note how idletasks does not update all new events. Try resizing the app while it counts, try moving a window in front of the app, then removing it. It should be more or less identical to before idletasks was added. Finally, change the sub to the following and rerun it.

sub runCounter { $counter = 0; while ($counter != 100000) { $counter++; $mw->update; } }

Now the app should be completely responsive to other events as it counts... a drawback of updating so often however is that it does add processing time to the sub to complete so it's fairly common to see code that only updates at certain intervals. Something like this perhaps:

$mw->update if $counter % 100 = 0;

Rob