use strict; use warnings; use threads; use Thread::Queue qw( ); use Time::HiRes qw( sleep ); use Tk qw( MainLoop ); my $q = Thread::Queue->new(); my $mw = MainWindow->new(); my $text = $mw->Entry(-width => 8)->pack(); $mw->repeat(100, sub { while (defined(my $command = $q->dequeue_nb())) { $text->delete('0.0', "end"); $text->insert('0.0', $command); $mw->update(); } }); # Some worker. async { for (;;) { sleep(0.2 + 1.5 * rand()); $q->enqueue(chr(ord('A') + rand(26))); } }->detach(); MainLoop();