Perl Monk, Perl Meditation | |
PerlMonks |
Re: Perl Tk and Threadsby zentara (Archbishop) |
on Dec 23, 2008 at 16:35 UTC ( [id://732320]=note: print w/replies, xml ) | Need Help?? |
Tk is not thread safe, but you can use threads with it with precautions.
1. The thread must be created before any Tk widgets are invoked. You violate that rule by creating the thread in a button callback. 2. Do not put any Tk code into the thread, and do not try to access Tk widgets from the thread. Use shared variables to communicate with the main thread, and have a timer or fileevent in the main Tk thread, read from the thread. Here is a very simple example (limited error checking) If you want to launch threads from GUI callbacks, you may have better luck with Perl/Gtk2; but even with it's thread-safety mechanism, it is still more foolproof to make your thread before any Gtk2 widgets are invoked. I'm not really a human, but I play one on earth Remember How Lucky You Are
In Section
Seekers of Perl Wisdom
|
|