You are running into the same roadblock everyone who runs threads with Tk encounters. You cannot pass a Tk widget to a thread, even if it isn't going to do anything. So that accounts for your "wrong pool" error, and there isn't anyway around it with Tk.

Now the question is "how to do it, while keeping the GUI thread-safe?" The #1 idea could be done by forking off and communicating with sockets....but that is probably harder than the threads.

#2b is the way I usually do it. Have shared variables, which can be set by the threads and read by the Main-GUI thread with a timer. When the GUI sees the flag, it processes the data for display, and possibly closes off the thread( or puts it to sleep for later use). A timer is not that much over head, and is a clean easy-to-use solution.

You can mix Gtk2( what Wx is based on) and Tk. But you will still have to use a timer to call the "do-one-loop" iteration of the secondary gui; that keeps the secondary gui from freezing. Here is a Tk MainLoop running a Gtk2 loop. (It can be done the other way too)

#!/usr/bin/perl -w use strict; use Gtk2; use Tk; my $mw = MainWindow->new(-title=>'Tk Window'); Gtk2->init; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Gtk2 Window'); my $glabel = Gtk2::Label->new("This is a Gtk2 Label"); $window->add($glabel); $window->show_all; my $tktimer = $mw->repeat(10, sub{ Gtk2->main_iteration while Gtk2->events_pending; }); $mw->Button(-text=>' Quit ', -command => sub{exit} )->pack(); MainLoop; ######################################## __END__

You might want to look at the newest Gtk2-Perl threads demo. They have an example that might be what you are looking for. They have a "thread-safe" mode that lets you share some widgets in threads, and "enter" and "leave" the thread to update the threaded widgets.


I'm not really a human, but I play one on earth. flash japh

In reply to Re: Tk and Threads (again) by zentara
in thread Tk and Threads (again) 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.