Hi lukaszt,

When you program in Tk, you have to change your mindset to think in terms of event-driven programming.

Here's an example of how you could use the Tk "repeat" function, to execute a command every second:

# Create a new main window object called $mw my $mw = new MainWindow(); # ... other GUI setup here # Call repeat to execute your subroutine every second (1000 millisecon +ds) my $loopStop = 0; # A pointer to this will be passed to the subrout +ine my $hour; # However this is calculated ... $mw->repeat(1000 => [ \&CheckTime, \$loopStop, $hour ]); MainLoop(); # The MainLoop goes last # And here's the subroutine + sub CheckTime { my ($ploopStop, $hour) = @_; $exeTime=18; if ($$ploopStop == 0) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $ZWIDGETS{'Text1'} -> insert('end',"Waiting......\n"); if ($hour == $exeTime) { $ploopStop = 1; $ZWIDGETS{'Text1'}->insert('end', "Starting.....\n"); } } return $hour; }

Note that you don't need to sleep in the subroutine; that would only slow down the entire GUI, as jdtoronto pointed out.

When the value of $hour (however you are calculating it) is equal to $exeTime, the variable pointed to by $ploopStop is set to 1, so on subsequent calls, the logicthe documentation for Tk::repeat to see how to cancel an event loop.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Tk and While Loop by liverpole
in thread Tk and While Loop by lukaszt

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.