I am trying to do here is to enter the time in first field and when I click on the Start button the time would be set by the value entered and started on top, showing today's date, time started and time left. I could also overwrite the value and by clicking again the timer would pickup from there. Now when a click on the stop button, I would like to set that value on the second entry box with the value of the first entry box, more like a pause button function. I am also thinking if it's possible to have some kind of warning to advise that the time is about to expire. I am new to this and if there is someone there to help me it would be very helpfull.
Thank you very much
Here is the code I have so far.

#! /perl/bin/perl5 -w use strict; use Tk; use Time::HiRes qw ( gettimeofday tv_interval ) ; my ( $mw , $msg , $msg2 , $mlabel , $id , $bf , $stime, $font_val) ; my @bgc =( "#000000"); my $main = MainWindow->new; $mlabel = $main->Label ( -textvariable => \$msg )-> pack ( -side => "t +op" ) ; $main->Label(-text => 'Enter Time')->pack; my $font = $main->Entry(-width => 20); $font->pack; my $filename = $main->Entry(-width => 20); $filename->pack; #test #$font = $main->Label(-textvariable => \$font_val);$font->pack; ## $main->Button(-text => 'Start', -command => sub{do_time($filename, $font)} )->pack( -side => "left", -padx => 5 ) ; $main->Button(-text => 'Print', -command => sub{do_print($filename, $font)} )->pack( -side => "left" , -padx => 5 ) ; $main->Button ( -text => "Exit" , -command => \&on_done )->pack ( -sid +e => "left", -padx => 5 ) ; $mlabel = $main->Button ( -text => "Start Timer" , -command => \&on_st +art )->pack ( -side => "left", -padx => 5 ) ; $main->Button ( -text => "Stop" , -command => \&on_stop )->pack ( -sid +e => "left" , -padx => 5 ) ; $main->Label(-textvariable => \$font_val)->pack( -side => "top" ); MainLoop; sub do_time { my ($file, $font) = @_; my $file_val = $file->get; my $font_val = $font->get; print "Now Time is $file_val in $font_val\n"; $main->Label(-textvariable => \$font_val)->pack( -side => "top" ); + } sub do_print { my ($file, $font) = @_; my $file_val = $file->get; my $font_val = $font->get; print "Sending file $file_val to printer in $font_val\n"; } sub on_done() { exit ; } sub on_timer() { my $t = time ; my @d = localtime $t ; my $elapsed; my $bc; $msg = sprintf ( "%04d-%02d-%02d %02d:%02d:%02d" , $d[5]+1900 , $d[4]+ +1 , $d[3] , $d[2] , $d[1] , $d[0] ) ; $elapsed = tv_interval ( $stime ) ; $msg = sprintf ( "%0.2f" , $elapsed ) ; # #my $bc = $bgc[ int($elapsed) % 8 ] ; #$main->configure ( -background => $bc ) ; #$bf->configure ( -background => $bc ) ; #return if $id ; #$stime = [gettimeofday] ; #$id = $mlabel; } sub on_start() { return if $id ; $stime = [gettimeofday] ; $id = $mlabel->repeat ( 50 , \&on_timer ) ; } sub on_stop() { return unless $id ; $id->cancel() ; $id = undef ; }

In reply to Computer User Timer by Anonymous Monk

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.