This is a very simple GUI timer done in Tk, and demos how you can have a background process running, and at the same time, still have GUI components response to user action normally. In this case the background process is the tick, and user can click reset button to reset the timer back to 0. In your case, just put the is_playing() checking in the repeat sub.
use Tk; use strict; my $mw = MainWindow->new(title => "Timer"); my $elapsed_sec = 0; my $elapsed_sec_label = $mw->Label(-textvariable => \$elapsed_sec)->pa +ck(); $mw->Button(text => "reset", command => sub {$elapsed_sec = 0})->pack( +); $mw->repeat(1000 => sub {$elapsed_sec ++}); #this is repeated every se +cond, and you can put your is_playing here MainLoop;
In reply to Re: setting up non-gui callbacks in Perl/Tk
by pg
in thread setting up non-gui callbacks in Perl/Tk
by forrest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |