fanticla has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I have a simple gui. Two buttons: "start" counting and "end" counting. Clicking on "start" , the script starts counting and prints out. I would like to be able to press anytime the button "stop" and stop the counting. While counting the Window is frozen.
#!/usr/bin/perl -w use strict; use warnings; use Tk; my $mw = MainWindow->new(); $mw->Button( -text => 'Start', -command => \&start_process )->pack; $mw->Button( -text => 'Stop', -command => \&stop_process )->pack; MainLoop; sub start_process{ my $count = 0; while ($count < 10) { print $count; sleep 1; $count ++; } } sub stop_process{ #stopping the process }
Even putting a $mw->update(); in the while loop (as suggested in other posts) doesn't change the behaviour. What is the best practice to keep the Window "alive" even while counting?
Thanks, cla
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stop counting (process)
by Anonymous Monk on Aug 25, 2010 at 01:11 UTC | |
by Anonymous Monk on Aug 25, 2010 at 06:50 UTC | |
|
Re: stop counting (process)
by zentara (Cardinal) on Aug 25, 2010 at 11:39 UTC | |
by fanticla (Scribe) on Aug 25, 2010 at 12:59 UTC | |
|
Re: stop counting (process)
by JavaFan (Canon) on Aug 24, 2010 at 23:00 UTC |