use Tk; use threads; use Thread::Queue; my $q = Thread::Queue->new(); my $thr = threads->create(sub { ###################################################### # thread working on input received from Tk MainWindow do { my $item = $q->dequeue(); print "Received: $item\n"; } while(1); ###################################################### })->detach(); ###################################################### # here comes the Tk stuff $mw=new MainWindow; $mw->repeat(1000,\&handler); MainLoop; sub handler { $i++; $q->enqueue("command $i"); } ######################################################