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

use Tk; $MW=MainWindow->new(-title=>'MyWindow'); $MW->Button( -text=>'change', -command=>\&change)->pack; $LB=$MW->Label(-text=>'...')->pack; MainLoop; sub change { $LB->configure(-text=>'case 1'); sleep 3; $LB->configure(-text=>'case 2'); }

When I clicked the button 'change',the button didn't rebound
until the call back function ended and I had never seen
'case 1' was printed but 'case 2'.
These two things are not my intentions.
I need your help,Thanks!

Replies are listed 'Best First'.
RE: A question about Tk.
by atl (Pilgrim) on Oct 12, 2000 at 15:39 UTC
    Quick help for the problem of never seeing "case 1": you need to tell the program to redraw the widget. One way (possibly not the best, but it works):
    sub change { $LB->configure(-text=>'case 1'); $LB->update; sleep 3; $LB->configure(-text=>'case 2'); }
    As for the problem of doing a longer job in the background while the GUI continues smoothly, I guess you'll have to programm a multitask/multiprocess script. How you do that depends on what exactly you want to do in the background job.

    Have fun ...

    Andreas