in reply to Does this Tk program require a thread?

In "Mastering Perl/Tk", pg 402, they discuss a $mw->repeat function. From looking at it briefly, it loks like you want:

$main->repeat(50 => \&run) MainLoop; sub run { $clip->WaitForChange(); # needs to NOT block. my $contents = $clip->Get(); if ($mode) { $clip->Set(uc($contents)); } }
EBut this is suposed to be a non-blocking routine, as run will be called every 50 milliseconds, so you need to rewrite that part to see if there's new clipboard content and return if not. If it blocks, MainLoop stops running.

ALthoough --Bob Niederman, http://bob-n.com

Replies are listed 'Best First'.
Re: Re: Does this Tk program require a thread?
by nysus (Parson) on Jul 15, 2003 at 01:03 UTC
    Not elegant by a long shot but it did the trick. Thanks for looking that up.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

      And, in case you haven't already looked it up, WaitForChange() accepts a millisecond time-out parameter. So, you can call $changed = $clip->WaitForChange(1); to get a "non-blocking" wait.

      bbfu
      Black flowers blossom
      Fearless on my breath

      You might also want to take a look at the Tk::After POD and the other methods it provides in addition to repeat() (like after(), afterIdle(), etc.).

      Also of interest would be waitVariable() and the other wait* methods (see Tk::Widget).