<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
######################################################################
# stopwatch.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

######################################################################
# stopwatch.pl: stopwatch with start/stop/reset function and GUI display
######################################################################
use Tk;
use Stopwatch;                     # include 'Stopwatch' class

my $top = MainWindow-&gt;new();
                                   # create label with dynamically 
                                   # modifiable text
$top-&gt;Label(-textvariable =&gt; \$stopwatch_display)-&gt;pack();

$top-&gt;Button(-text    =&gt; "Start",  # Start button
             -command =&gt; sub { $sw-&gt;start() })-&gt;pack(-side =&gt; "left");

$top-&gt;Button(-text    =&gt; "Stop",   # Stop button
             -command =&gt; sub { $sw-&gt;stop() })-&gt;pack(-side =&gt; "left");

                                   # Reset button (reset with
$top-&gt;Button(-text    =&gt; "Reset",  # simultaneous stopwatch update)
             -command =&gt; sub { $sw-&gt;reset(); update_func($sw) }
            )-&gt;pack("-side" =&gt; "left");

$top-&gt;Button(-text    =&gt; "Exit",   # Exit button
             -command =&gt; sub { exit(0) })-&gt;pack("-side" =&gt; "left");
  
                                   # new stopwatch
$sw = Stopwatch-&gt;new(\&amp;update_func, 1000);

update_func($sw);                  # display at 00:00:00

MainLoop;                          # main event loop

######################################################################
sub update_func {
######################################################################
# read seconds counter of the stopwatch, convert into HH:MM:SS-Format
# and set the variable $stopwatch_display
######################################################################
    my $self = shift;

    $seconds = $self-&gt;gettime();   # stopwatch time check

                        # seconds -&gt; HH:MM:SS 
                        # gmtime(0) is 00:00:00, localtime() in GMT
    ($sec, $min, $hour) = gmtime($seconds);

                                   # set GUI display
    $stopwatch_display = sprintf("%02d:%02d:%02d", $hour, $min, $sec);
}

</pre></body></html>