Main Content

Perl/Tk real time display

Archive - Originally posted on "The Horse's Mouth" - 2006-02-10 00:38:42 - Graham Ellis

It's a real pleasure to be having an opportunity at the tail end of this week to write some examples that are combining Perl, Tk, and OO techniques. This clock is generated on a canvas, and updates every second. It's generated in its own frame and schedules its own events, so you could easily use it within part of your own GUI if you wished. The hour, minute and second markers are all instances of an object of class hand, also defined within the example, and all the calls to the trig functions that are needed to work out the hand mappings and movements are encapsulated in there.

Tk's powerful canvas handling tools allow the text to be centred without complex calculations, and the display list technology it uses allows the hand markers to be moved without the need for repaint routines - it's truly impressive what can be done within a very few Kbytes of source