in reply to Re: PerlTk Busy vs. update
in thread PerlTk Busy vs. update

I thought so too, but I seem to be able to hit my Quit button despite the fact that I'm seeing the hourglass (universal sign for "you shouldn't be able to hit the Quit button now")

Any thoughts on the merits of idletasks() vs update() ?

Replies are listed 'Best First'.
Re^3: PerlTk Busy vs. update
by eserte (Deacon) on Jul 02, 2004 at 08:41 UTC
    The difference is that idletasks() only serves IDLE_EVENTS (for example those callbacks defined with the afterIdle method), while update() serves all events. When in doubt use update().
Re^3: PerlTk Busy vs. update
by keszler (Priest) on Jul 02, 2004 at 07:43 UTC
    If I've got this right, you're setting $main->Busy, calling $label->update, and seeing responses to events - like a buttonclick on another widget - occur when the child widget performs the update. Are you setting -recurse => 1 in the call to Busy?

    (I always set that, except in exceptional circumstances, and so ass-u-me-d that $child->update would not affect $otherchild.)

      You've got it right, and I am setting -recurse=>1 but as pointed out below, the update acts globally.

      Does anyone know what the behavior of setting (un)Busy an already (un)Busy widget is "supposed" to be?

      I think this might be my problem.

        Is that with $top->update or $label->update?

        Contrary to the assertion that any update is global, the 2nd run of my test script shows that with Busy(-recurse=>1) and $label->update, the $button event was discarded. (On the Win98 and W2K boxen here, anyway.)

        Update: I'd changed two things at once while testing - the recurse option was solely responsible for causing the events to be discarded. Update is global.

        Also, idletasks is slightly different between the Win* and Linux boxen I use. On the Linux boxen there are no "leftover" characters after idletasks causes the label change to display.

Re^3: PerlTk Busy vs. update
by keszler (Priest) on Jul 02, 2004 at 14:14 UTC
    Idletasks will change a label, but not perform other needed tasks. For example:
    #!perl use strict; use warnings; use Tk; my $top = MainWindow->new(); my $txt = $top->Text->pack; for my $t ('a' .. 'z') { $txt->insert('end', $t x 40 . "\n"); } my $lbltxt = "wowowowowowowowowowowowowowo"; my $label = $top->Label(-textvariable => \$lbltxt)->pack; my $button = $top->Button(-text => "Die", -command => sub { exit; })-> +pack; $top->update; #$top->Busy(-recurse => 1); # use $top->Busy; # drop sleep 8; $lbltxt = "updatedupdated"; #$label->update; # use $label->idletasks; # drop sleep 8; $txt->delete('1.0','end'); $top->Unbusy; Tk::MainLoop;
    Run this, click on the "Die" button as soon as the window appears. After the first sleep, the label is changed, but since the new text is of shorter length several "wowo" characters remain on either side of "updated". After the 2nd sleep and the Unbusy, the "Die" event occurs and the program exits.

    Comment out the "drop" lines and uncomment the "use" lines.

    Run now, click "Die" before the label changes. This time there are no leftover characters, and the "Die" event is discarded. After the Unbusy the program continues.

      I get different behavior than you describe (running on my Sun box). There are no "leftover characters" either way, but as noted the "Die" event is only discarded if -recurse=>1 is set. Perhaps this is a portability issue?
        That seems to be the case - running it on a Linux box here leaves no leftovers either. With recurse, the "Die" event is discarded during the ->update, or after the Unbusy with idletasks.