in reply to PerlTk, how to handle/setup an "autorun" block with the GUI?
#!/usr/bin/perl use Tk; use warnings; use strict; my $mw = MainWindow->new(title => "Timer"); my $elapsed_sec = 0; my $elapsed_sec_label = $mw->Label(-textvariable => \$elapsed_sec)->pa +ck(); my $repeater; # declare first so it can be accessed in the callback $mw->Button(-text => "reset", -command => sub { $elapsed_sec = 0; &repeater(); })->pack(); $mw->Button(-text => "exit", -command => sub { exit })->pack(); # start first run &repeater(); MainLoop; sub repeater{ #this is repeated every second, and you can put your is_playing here $repeater = $mw->repeat(1000 => sub { $elapsed_sec ++; if ($elapsed_sec > 4){ $repeater->cancel } } ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PerlTk, how to handle/setup an "autorun" block with the GUI?
by exilepanda (Friar) on Feb 22, 2013 at 14:42 UTC |