Tkinter listener thread?

Grant Edwards grante at visi.com
Thu Jan 26 12:46:21 EST 2006


On 2006-01-26, Steve Holden <steve at holdenweb.com> wrote:
> gregarican wrote:
>> I have a Python UDP listener socket that waits for incoming data. The
>> socket runs as an endless loop. I would like to pop the incoming data
>> into an existing Tkinter app that I have created. What's the
>> easiest/most efficient way of handling this? Would I create a separate
>> thread that has the listener set a certain Tkinter variable if there is
>> incoming data? Any suggestions would be tremendously appreciated :-)
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965

That seems a bit complex.  Why not just register the file
descriptor and read-handler with Tk?

http://www.faqts.com/knowledge_base/view.phtml/aid/3728

That way the read-handler gets called by Tk's event loop
anytime there's receive data waiting.  No extra thread, no
synchronization worries.

If the read-handler takes a _long_ time to complete, it does
make your GUI pause, so that may be a concern.

Unless tk.createfilehandler isn't supported no Wni32
platforms??

-- 
Grant Edwards                   grante             Yow!  Gee, I feel kind of
                                  at               LIGHT in the head now,
                               visi.com            knowing I can't make my
                                                   satellite dish PAYMENTS!



More information about the Python-list mailing list