See How to implement a timer in perl?, and ......
#!/usr/bin/perl -w # # This script generates a counter with start and stop buttons. Exit w +ith # Ctrl/c or Ctrl/q. # # This a more advanced version of `timer', where we conform to a stric +t style # of Perl programming and thus use lexicals. Also, the counter is upd +ated via # a -textvariable rather than a configure() method call. # # Tcl/Tk -> Perl translation by Stephen O. Lidie. lusol@Lehigh.EDU 9 +6/01/25 require 5.002; use Tk; use strict; sub tick; my $MW = MainWindow->new; $MW->bind('<Control-c>' => \&exit); $MW->bind('<Control-q>' => \&exit); # %tinfo: the Timer Information hash. # # Key Contents # # w Reference to MainWindow. # s Accumulated seconds. # h Accumulated hundredths of a second. # p 1 IIF paused. # t Value of $counter -textvariable. my(%tinfo) = ('w' => $MW, 's' => 0, 'h' => 0, 'p' => 1, 't' => '0.00') +; my $start = $MW->Button( -text => 'Start', -command => sub {if($tinfo{'p'}) {$tinfo{'p'} = 0; tick}}, ); my $stop = $MW->Button(-text => 'Stop', -command => sub {$tinfo{'p'} = + 1;}); my $counter = $MW->Label( -relief => 'raised', -width => 10, -textvariable => \$tinfo{'t'}, ); $counter->pack(-side => 'bottom', -fill => 'both'); $start->pack(-side => 'left', -fill => 'both', -expand => 'yes'); $stop->pack(-side => 'right', -fill => 'both', -expand => 'yes'); sub tick { # Update the counter every 50 milliseconds, or 5 hundredths of a s +econd. return if $tinfo{'p'}; $tinfo{'h'} += 5; if ($tinfo{'h'} >= 100) { $tinfo{'h'} = 0; $tinfo{'s'}++; } $tinfo{'t'} = sprintf("%d.%02d", $tinfo{'s'}, $tinfo{'h'}); $tinfo{'w'}->after(50, \&tick); } # end tick MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: A timer in Tcl/Tk in Perl::Tk by zentara
in thread A timer in Tcl/Tk in Perl::Tk by pashanoid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.