Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: PerlTk, how to handle/setup an "autorun" block with the GUI?

by zentara (Archbishop)
on Feb 22, 2013 at 11:24 UTC ( [id://1020138]=note: print w/replies, xml ) Need Help??


in reply to PerlTk, how to handle/setup an "autorun" block with the GUI?

Here is a simple usage of a timer. Tk::after and Tk::repeat both do the same thing, but Tk::after runs just once, where Tk::repeat continues until you stop it.
#!/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 } } ); }

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: PerlTk, how to handle/setup an "autorun" block with the GUI?
by exilepanda (Friar) on Feb 22, 2013 at 14:42 UTC
    Thank you very much! Your code demonstrated an alternative style from what the perldoc mentioned! Works perfectly and much easier for me to deploy!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1020138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found