Part of your problem is that you are starting up two event loops which don't seem to be yielding control to each other. Using Tk under POE ia a different kettle of fish from using it directly. You need to constantly be aware what part of the event loop has control and to delegate control to the appropriate event handlers when necessary.

Maybe this will help illustrate. Here's a contrived example. A text widget is constantly being filled with random numbers while being searched for strings of 12 odd digits in a row. When one is found, it pauses until you tell it to search again.

use warnings; use strict; use Tk; use POE; POE::Session->create ( inline_states => { _start => \&startApplication, search_again => \&search_again, search => \&searchUpdate, } ); $poe_kernel->run(); exit 0; sub startApplication { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; $poe_main_window->Label( -text => 'Search for at least 12 odd random digits in a row' )->pack; $heap->{text} = $poe_main_window->Text->pack(-expand => '1', -fill + => 'both'); $heap->{text}->tagConfigure('highlight', -background => 'orange'); $heap->{search_run} = 1; $heap->{search_index} = '1.0'; $poe_main_window->Button( -text => "Search Again", -command => $session->postback('search_again') )->pack; $kernel->yield('search'); } sub searchUpdate { if ($_[HEAP]->{search_run}){ my $count; my $search_index = $_[HEAP]->{text}->search( '-regexp', -count => \$count, '--', '[13579]{12,}', $_[HEAP]->{search_index}, $_[HEAP]->{search_index}.' lineend' ); if ($search_index){ $_[HEAP]->{text}->tagAdd('highlight', $search_index, $sear +ch_index." +$count".'c'); $_[HEAP]->{search_run} = 0; $_[HEAP]->{search_index} = $_[HEAP]->{text}->index($search +_index."+$count".'c'); } if ($_[HEAP]->{search_run}){ my $line; for (0..69){ $line .= int rand 10; } $_[HEAP]->{text}->insert('end',"$line\n"); if ($_[HEAP]->{text}->index('end') > 25){ $_[HEAP]->{text}->delete('1.0','1.0 lineend +1c'); $_[HEAP]->{search_index} = '1.0'; } } } $_[KERNEL]->yield('search'); } sub search_again { $_[HEAP]->{text}->tagRemove('highlight', '1.0', 'end'); $_[HEAP]->{search_run} = 1; $_[KERNEL]->yield('search'); }

In reply to Re: POE, Tk, Simultaneous problem! by thundergnat
in thread POE, Tk, Simultaneous problem! by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.