G'day simonz,
Welcome to the monastery.
That's actually a rather vague question; however, the mechanism you're probably looking for is the callback (see Tk::callbacks).
A Tk application is event-driven. You don't write code that waits for some event to occur (or complete), you associate a callback with the event which is called when that event occurs (or completes). Here's some examples:
-
Don't wait for entries to appear in a log file (e.g. "while (<$log_fh>) {...}"). Associate a Tk::fileevent callback with the event of the log file having data to read (e.g. "$mw->fileevent($log_fh, 'readable', $callback)").
-
Don't use a sleep statement to delay doing something until the sleep completes (e.g. "sleep $secs; do {...}"). Associate a Tk::after callback with the completion of the delay (e.g. "$mw->after($millisecs, $callback)").
-
You can use Tk::bind to associate callbacks with all sorts of keyboard, mouse and GUI activities.
-
The -command option of Tk::Button (and similar widgets) takes a callback as its value.
If the processing involved with a callback takes an inordinate amount of time to complete, then you may need a separate process so that the Tk process doesn't block. That could involve threads or forking a child process (see perlipc).
Here's a fairly straightforward way of forking a long running process, using open and Tk::fileevent, that won't block while waiting for the child process to return output:
open my $pipe, '-|', 'long_running_process.pl';
$mw->fileevent($pipe, 'readable', $callback);
As I said at the start, your question is rather vague.
The information I've provided here should be sufficient for dealing with the usual culprits.
If you're having difficulty with a particular problem that I haven't addressed, post specific information and we can look at it.
If you do need to post a follow-up question, please follow the guidelines in "How do I post a question effectively?": a better question gets better answers.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.