Simple demonstration of self refreshing Tk window using the system clock. I'd love to improve this to query a few NTP servers so that I can get the correct time even on a computer where I don't have admin rights and can't set up a full NTP client.
#!perl -w use strict; use Tk; my $mw=MainWindow->new(-title=>'Time'); my $cv=$mw->Canvas(-height => 25, -width => 150)->pack; my $i=0; my $l=undef; sub t { $cv->delete( $l ) if defined $l; $l = $cv->create( 'text', 75, 15, -text => scalar( localtime( time +() ) ) ); } $cv->repeat( 250, \&t, $cv ); MainLoop

Replies are listed 'Best First'.
Re: Simple Tk Clock
by jdhedden (Deacon) on Jul 13, 2005 at 18:38 UTC
    You don't need NNTP, just HTTP. You can get the time from NIST using the code at this node. It should be trivial to integrate the two bits of code together into something acceptable.

    Remember: There's always one more bug.
      What would be even better is to use whatever NTP / NIST time-getting solution to set your computer's clock; that way, not only this, but every other time-referencing program will have the right time. There's a reason time() is a system call.
Re: Simple Tk Clock
by jdporter (Paladin) on Jul 13, 2005 at 18:41 UTC
    Interesting. I'd do it this way (golfish):
    use Tk; use strict; my $mw = new MainWindow -title => 'Time'; (Label $mw -textvariable => \my $t )->pack; repeat $mw 1000, sub { $t = localtime }; MainLoop;
Re: Simple Tk Clock
by Anonymous Monk on Jul 13, 2005 at 17:55 UTC
    oops, forgot to remove the line 'my $i = 0;' I originally tested this with a simple counter.