in reply to Tk with threads

Tk and threads can be even more problematic than the usual range of problems with thread handling in Perl. The key is to create any threads you want to use before you call any Tk code and make sure you don't include Tk code in the threaded code.

If those constraints sound bothersome then you may be able to solve the problem using POE and Tk, but a little Super Searching indicates that Tk and POE tend to fight somewhat too.


Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Tk with threads
by shmem (Chancellor) on May 12, 2008 at 07:52 UTC

    I can't see how POE and Tk are fighting - they cooperate. POE queues the main window's destroy event and passes control to Tk. POE code is called from Tk's event dispatcher; then POE uses Tk's event loop handler inside it's own event loop to serve Tk events from inside it's own event loop.

    But if by fighting you mean loading order you're right - POE has support for Tk, not the other way round, so you have to load POE first, and access the Main Window via $poe_main_window:

    use POE qw(Loop::Tk); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("next") }, next => sub { print "tick...\n"; $_[KERNEL]->delay(next => 1); }, }, ); $button = $poe_main_window->Button( -text => 'Press me', -command => sub { exit; }, )->pack(); $poe_kernel->run();

    I haven't found a way (yet) to successfully load POE at some time within a running Tk application and shoehorn its event dispatcher somehow into the Tk event loop.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}