Author image Anthony Fletcher
and 1 contributors


Tk::StrfClock - a X/TK digital clock widget based on strftime.


  use Tk::StrfClock;

        -type   => [Label|Button|Menubutton|Optionmenu],
        -format => <strftime format string>,
        -update => [<seconds>|s|m|h|d],
        -advance => [<seconds>],
        -action => <pattern matching action>,
        -ontick => <function>,


Tk::StrfClock is a string clock widget based on one of a Tk::Label, a Tk::Button, a Tk::Menubutton or a Tk::Optionmenu (chosen at creation time). The current date and time (in some chosen configuration) is displayed as the text in the base widget.


All the base widget options are available.

-type => [Label|Button|Menubutton|Optionmenu],

Set the base widget type at creation time. This cannot be configured thereafter. The default is Tk::Label.

-format => <strftime format string>

Sets the required date/time format using POSIX strftime format. The default is %c.

-update => <seconds>|s|m|h|d|a

Sets how often the clock is updated. If set to the characters s, m, h, d or a then the clock is updated exactly on the second, minute, hour, day or is automatically guessed.

The default is a.

-advance => <seconds>

Sets the clock fast or slow this many seconds. The default is 0.

-action => <pattern matching action>

Sets a pattern matching action to be applied to the date string before it is displayed. The default is to do nothing.

-ontick => <function>

Set a function to be run every tick of the clock. The default is none.


  use Tk;
  use Tk::StrfClock;

  my $top=MainWindow->new();


Run the module itself to start a test program. To increase the size of the fond add something like

     *StrfClock*font: -*-fixed-medium-r-normal--20-*-*-*-*-*-*-*

to your .Xdefaults file.


See Tk for Perl/Tk documentation.


Anthony R Fletcher, <a r i f 'a-t' c p a n . o r g>


Copyright (C) 1998-2014 by Anthony R Fletcher. All rights reserved. Please retain my name on any bits taken from this code. This code is supplied as-is - use at your own risk.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.