I'm trying to get the hang of perl Tk. I thought an extreamly simple clock would be a good project. Getting the time is easy enough, as is displaying it. But what I want is a label that updates every second.

Anyway I went through the tk documentation, but it is very short on code examples, I tried to used the Tk::After method, but I didn't do anything new, I just get a window with a static time. I couldn't find anything I could use when I did a super search. Can someone point me in the right direction?

My project so far:

#!/usr/bin/perl use Tk; $top = new MainWindow; $id = Tk::After->new($top->Label(-text =>&gettime)->pack,1000,'rep +eat',\&gettime); MainLoop; sub gettime{ ($sec,$min,$hour,$day,$month,$year,$wday,$yday,$isDST) = localtime +(); @mname=("January","February","March","April","May","June", "July","August","September","October","November","December +"); @weekday=("Sunday","Monday","Tuesday","Wednesday","Thursday","Frid +ay","Saturday"); for($sec,$min){$_="0$_"if($_<10);} $dst = $isDST?"Daylight Savings Time":"Standard Time"; $year = $year +1900; $timestring= "$weekday[$wday] $mname[$month] $day," . $year . " $h +our:$min:$sec$x\n"; }

In reply to Refresh Display in Perl Tk by thunders

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.