473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tkinter listener thread?

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 :-)

Jan 26 '06 #1
6 3194
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/Coo...n/Recipe/82965
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Jan 26 '06 #2
On 2006-01-26, Steve Holden <st***@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/Coo...n/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!
Jan 26 '06 #3
Grant Edwards wrote:
Unless tk.createfilehandler isn't supported no Wni32
platforms??


Unfortunately that's the case. As of Python 2.3.4 under Windows XP the
createfilehandler method isn't available. It's only for UNIX as Mac
platforms AFAIK. Shame, as it would be relatively easy to implement.
Instead I'll look to set/check some global flags to hopefully get
things working smoothly. Using Qt it's so much easier. Some apps I used
the QThread class, while others I just set as QTimer instance to run a
regular background process :-(

Jan 26 '06 #4
Steve Holden wrote:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/82965


Thanks. I tried a variation of this Queue posting/Flag checking method
and it worked to a tee. The problem was that my UDP socket query was
blocking things so that thread was hanging everything up. So I used a
socket timeout value along with a try: except: construction to query
the socket for data. Now it's fine.

Jan 26 '06 #5
On Thu, 26 Jan 2006 17:32:32 +0000, Steve Holden <st***@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/Coo...n/Recipe/82965


There's in fact no need to check regularly if there's something in the
Queue: the secondary thread can post a tk custom event to trigger the
treatment automatically from within the main GUI loop. See here:
http://minilien.fr/a0k273

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
Jan 27 '06 #6
Eric Brunel wrote:
There's in fact no need to check regularly if there's something in the
Queue: the secondary thread can post a tk custom event to trigger the
treatment automatically from within the main GUI loop. See here:
http://minilien.fr/a0k273


Appreciate the suggestion. This further helps simplify things. So far
so good getting the UDP listener to work well within Tkinter. This
listener takes an incoming CTI screen pop of the caller ID and queries
it against a CRM database to bring up the appropriate contact record if
applicable. One of these days I need to port the CTI library over from
Ruby into Python so I don't have to rely on a UDP socket connection and
can just pass the data natively within Python. But this is a workaround
until that day comes.

Thanks again. I am very impressed with the Python community in terms of
knowledge and helpfulness. It's made matters a lot easier for this
particular Python newbie...

Jan 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
2
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another...
2
by: John Pote | last post by:
Running my programme in Python 2.3.4 I received the following msg in the consol :- (Pent III running W2K prof) """ Exception in Tkinter callback Traceback (most recent call last): File...
8
by: Erik Johnson | last post by:
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I...
2
by: Mark English | last post by:
Is there a safe way to run tkinter in a multithreaded app where the mainloop runs in a background thread ? Here's some test code demonstrating the problem. I'm running Python2.4 under Windows...
14
by: Hendrik van Rooyen | last post by:
Hi, I get the following: hvr@LINUXBOXMicrocorp:~/Controller/libpython display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is...
0
by: cuso | last post by:
I have one problem with the following code: from win32com.client import constants import win32com.client import win32gui import pythoncom from Tkinter import * class SpeechRecognition: ...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
0
by: Steve Holden | last post by:
Allen Taylor wrote: You can publish it in the Python package index - see http://pypi.python.org/pypi/ If you want to have it considered for inclusion into future versions of Python then you...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.