in reply to Interrupting Tk repeat() method
The other way is to use after(). after() will only be triggered once, thus the event handler will only be called once. Inside the event handler, based on the situation, you can decide whether to reschedule itself again. If yes, simply call after() to reschedule itself. For example:
use Tk; use Tk::MListbox; my $mw = MainWindow->new(); my $count_v = 0; my $stop_v = 0; my $stop = $mw->Checkbutton(-text => "stop", -variable => \$stop_v, -c +ommand => \&schedule)->pack(); my $count = $mw->Label(-text => $count_v)->pack(); $count->after(1000, \&inc); MainLoop; sub inc { $count->configure(-text => $count->cget("-text") + 1); if (!$stop_v) { $count->after(1000, \&inc); } } sub schedule { if (!$stop_v) { $count->after(1000, \&inc); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interrupting Tk repeat() method
by zentara (Cardinal) on Sep 19, 2005 at 10:55 UTC |