nysus has asked for the wisdom of the Perl Monks concerning the following question:
Even though I'm new to Tk, I was pretty sure the above code wouldn't work. Sure enough, it doesn't. I'm guessing it's because the infinite loop, outside of the 'MainLoop,' never gets executed. So am I going to need a thread here? I've dabbled with threads in Java. But I'm not familiar with threading at all with Perl and I hear it's kind of a nightmare. Is there a more obvious technique I could be using that I'm missing?use strict; use Win32::Clipboard; use Tk; my $change_mode = \&change_mode; my $mode = 0; my $clip = Win32::Clipboard(); my $main = new MainWindow; $main->Label(-text => 'Clipboard Case Changer' )->pack; $main->Button(-text => 'On/Off Toggle', -command => $change_mode )->pack; MainLoop; sub change_mode { $mode = !$mode; } #Change clipboard contents to uppercase, if $mode == 1; while(1) { $clip->WaitForChange(); my $contents = $clip->Get(); if ($mode) { $clip->Set(uc($contents)); } }
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Does this Tk program require a thread?
by bobn (Chaplain) on Jul 15, 2003 at 00:52 UTC | |
by nysus (Parson) on Jul 15, 2003 at 01:03 UTC | |
by bbfu (Curate) on Jul 15, 2003 at 01:28 UTC | |
by William G. Davis (Friar) on Jul 15, 2003 at 07:14 UTC |