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); } }
In reply to Re: Interrupting Tk repeat() method
by pg
in thread Interrupting Tk repeat() method
by aplonis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |