Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to change a Tk object's property from a thread

by ikegami (Patriarch)
on Aug 04, 2011 at 23:57 UTC ( [id://918667]=note: print w/replies, xml ) Need Help??


in reply to How to change a Tk object's property from a thread

Wrong question. Correct question: How do you notify Tk's thread that a property should be changed?

You could poll a Thread::Queue.

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();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://918667]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found