473,789 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3204
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***@holdenwe b.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.createfileha ndler 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.createfileha ndler isn't supported no Wni32
platforms??


Unfortunately that's the case. As of Python 2.3.4 under Windows XP the
createfilehandl er 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***@holdenwe b.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.zmz 5(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
3861
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 based on a Text widget with embedded windows and a thread running the Tkinter mainloop plus several other thread dealing with the scheduling of the contents and the acquisition of data but not using graphic widgets. I run the same code on Linux...
2
4402
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 thread for recording the frame rates (using a progress bar for visulization). The whole application worked very well once it received image data from the socket. The problem is when I tried to close that display window (click on the standard...
2
3430
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 "c:\apps\python\234\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "c:\apps\python\234\lib\lib-tk\Tkinter.py", line 459, in callit
8
4499
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 happen to already own John Grayson's book about Tkinter programming, so that is rather handy if I decide to use Tkinter. I have done some things slightly more involved than "Hello World" in Tkinter - I have never used wxPython. So, basically the...
2
3595
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 2000. ----------------Code snip starts------------- from Tkinter import * def GetTkinterThread():
14
2696
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 most frustrating, as there is no friendly traceback to help me guess where its coming from.
0
974
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: def __init__(self, wordsToAdd):
44
5010
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 processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
918
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 should post a bug to bugs.python.org wiht your patch as an attachment and the test of the above mail as a rationale for the change. Thanks for going to these lengths to contribute!
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.