Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl/Tk - Tk::Clock

by PERLscienceman (Curate)
on Jul 17, 2003 at 02:53 UTC ( [id://275094]=CUFP: print w/replies, xml ) Need Help??

At work I code by the ton. At home I could for fun; experimenting with Tk and whatever other cool modules I might happen to stumble upon; to learn new things and tinker around with that which is cool (which would be just about anything PERL)

This time it is about as simple as it gets. Poking around the world of CPAN I found the module Tk::Clock. In a nutshell, this Tk module generates a digital clock face, analog clock face or both. I decided to assemble the script so that it generated a "BIG classic analog clock". The module allows for manipulation of the colors of the hands and tick marks. In addition, in this particular script, I have played around restricting resizing of the Tk GUI (I read about it in one of the major Perl Books). Anyway enough said. The code is posted below.

As always, any feedback is greatly appreciated! Enjoy!

Learning Is What Makes Life Interesting... And PerlMonks Is A Great Part Of Learning!


#!/usr/bin/perl -w use Tk; use Tk::Clock; my $MW=MainWindow->new(); ### --- Prevents Main Window Resizing $MW->bind('<Configure>' => sub{ my $xe = $MW->XEvent; $MW->maxsize($xe->w, $xe->h); $MW->minsize($xe->w, $xe->h); }); $MW->title("My Analog Clock"); $clock = $MW->Clock(); $clock->config( useDigital => 0, useAnalog => 1, anaScale => 880, handColor => 'Green4', secsColor => 'Red2', tickColor => 'Black', ); $clock->pack(); MainLoop();

Replies are listed 'Best First'.
Re: Perl/Tk - Tk::Clock
by zentara (Archbishop) on Jul 17, 2003 at 15:11 UTC
    Hi, yeah, I've adopted tk-clock along time ago for my clock. I have a very minimalist desktop, and all I wanted was a tiny digital clock in the lower right hand corner. It also stays on top across my 10 virtual desktops. I've shown how to cut off the date too. I have a 1024x768 desktop, so you may have to adjust the geometry for your desktop.
    #!/usr/bin/perl use Tk; use Tk::Clock; my $m = MainWindow->new(); #$m -> geometry("70x30+930+740"); #with date $m -> geometry("70x15+940+755"); #no date $m->overrideredirect(1); #no xterm decorations my $c = $m->Clock (-background => "Black"); $c->config ( useAnalog => 0, useDigital => 1, # tickColor => "Orange", # handColor => "Red", # secsColor => "Green", timeColor => "lightBlue", # timeFormat => "hh:MM A", timeFormat => "HH:MM:SS", # dateColor => "Gold", # dateFormat => "m/d/y", timeFont => "-misc-fixed-medium-r-normal--13-*-75-75-c-*-iso8859- +1", ); $c->pack; MainLoop;
      Greetings! Thank you for your response. Since you mentioned small digital clocks based on Tk; here is another one, even simpler than the first. It is based on the Tk::StrfClock module. All of about 6 lines of code to get it going, it generates a small Tk Widget with date and time.

      Here is the code, very simple. Enjoy!

      #!/usr/bin/perl -w use Tk; use Tk::StrfClock; my $top=MainWindow->new(); $top->StrfClock()->pack(); MainLoop();
        Hey that last (short one) looks like a winner. However, I don't see it in the ActiveState list. Thats where I get my modules from for Win32 system.
Re: Tk::Clock
by Anonymous Monk on Jul 28, 2003 at 00:57 UTC
    Found Tk::Clock a few minutes ago on CPAN. Did a search to see if anyone had an example implementing it... ended up here. Looks cool. Was looking for a way to have a graphical clock. I looked into the Time() modules, but they basically only provide a time-stamp, no continous time. This module works great.
Re: Perl/Tk - Tk::Clock
by Anonymous Monk on Sep 04, 2003 at 09:44 UTC
    very good clock-sathiyan erode

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://275094]
Approved by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-16 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found