in reply to stop counting (process)

Never use sleep() in a Tk (or any gui ) unless it is in it's own thread. Here is how I would do it, use a timer.
#!/usr/bin/perl -w use strict; use warnings; use Tk; my $timer; 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; $timer = $mw->repeat(1000, sub{ if ( $count < 10 ){ $count++ ; print "$count\n";} }); } sub stop_process{ #stopping the process $timer->cancel; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: stop counting (process)
by fanticla (Scribe) on Aug 25, 2010 at 12:59 UTC

    The examples work fantastically

    Thank you all