Hi there,

pg is completely correct - look up Tk::after - using after or repeat is the way to do this. But on a side note, if your program is not going to be interactive you don't *need* to use MainLoop.

(I don't know why I'm mentioning this - I have a bad habit of bringing up the Wrong Way To Do It, just because I think it's interesting. I can feel the -- already.)

Instead of calling MainLoop you can write you own loop at the end that looks something like this:

while (1) { &refresh; $mw->update; sleep 1; }
But don't do that! The only good excuse that I can think of for doing something like this is if you want to popup a Tk status bar as your MainWindow while a script is doing something in the background (like parsing a really big file). In that case you don't need the interaction and the user is just sitting there and waiting for your script to stop running anyway.

By the way - I applaud your use of strict (and presumably warnings), but even with your my scoping your @blocks array is still being treated as a global. My preference is to pass a reference to you array around instead of just implying that you mean to use it globally.

What I like to do is create a $w hash and a $s hash and fill them with widgets and state information, then pass them to functions or Tk callbacks via reference. Of course, that is just a poor-persons form of OO, and works fine for simple scripts. This is what I mean:

use strict; use warnings; use Tk; my $widgets = {}; $widgets->{main} = MainWindow->new; $widgets->{button} = $widgets->{main}->Button( -text => "Whatever you do - don't push me", -command => [ \&callme, $widgets ] )->pack; MainLoop; sub callme { my $w = shift; $w->{main}->configure(-title => 'How dare you push me!'); # Anything else in the $widgets hash is available here # too - handy if you have lots of widgets you need to # control from your functions or methods. }
Anyway - just some food for thought. TMTOWTDI.
{NULE}
--
http://www.nule.org

In reply to Re: Tk version Geek clock by {NULE}
in thread Tk version Geek clock by Gorilla

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.