473,385 Members | 1,645 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,385 software developers and data experts.

tkinter, sockets and threads together

hello,

i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.

what's up with that?

thanks so much for your time!
julia
Jul 18 '05 #1
4 7506
ju************@hotmail.com (Julia Goolia) writes:
i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.

what's up with that?


On Unix, you can use Tk file handlers for sockets, i.e. have Tcl
select(2) not only on the connection to the X11 server (which is a
socket itself), but also select on your sockets. This is readily
supported in _tkinter.

On Windows, you have no choice but to use threads. If the socket
processing threads have no relationship to the Tk thread, everything
is fine. However, in many cases, interaction of some kind is
needed. In this case, it is ok to call Tk methods from other threads,
as long as they translate to "fast" commands, i.e. commands that only
modify state, but don't block - you should not run the mainloop in
multiple threads.

Regards,
Martin

Jul 18 '05 #2
In article <79**************************@posting.google.com >,
ju************@hotmail.com (Julia Goolia) wrote:
hello,

i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.

what's up with that?


For reading from a socket you can use file events. See Tkinter Summary
at my site <http://www.astro.washington.edu/owen/> for the basics.

To avoid blocking while writing (i.e.queue up the output data and write
it as the network permits), I ended up using threads. There are probably
other options.

The package "RO Util", available at th web site mentioned above includes
a simple class RO.Comm.TkSocket that handles input and output nicely,
while hiding the details of file events and the writing thread.

You could also use the Twisted Framework. It is reportedly well done and
integrate nicely with Tkinter and other frameworks. I can't speak from
personal experience as I've not yet tried it.

-- Russell
Jul 18 '05 #3
> i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.


Take a look at
http://www.python.org/doc/faq/gui.ht...ndled-while-wa
iting-for-i-o
RT

Jul 18 '05 #4
"Julia Goolia" <ju************@hotmail.com> wrote in message
news:79**************************@posting.google.c om...
hello,

i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.

what's up with that?

thanks so much for your time!


Well, one page worth reading would be Jacob Hallén's

http://aspn.activestate.com/ASPN/Coo...n/Recipe/82965

recipe, which IIRC is pretty general.

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/


Jul 18 '05 #5

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

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
5
by: george.trojan | last post by:
My application consists of Tkinter GUI that has to communicate with a remote server. The communication is bi-directional: the GUI responds to remote requests and user actions uch as pressing a...
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...
0
by: Rod Stephenson | last post by:
I am developing an engineering application for modelling multiphase flows in large pipe networks, and have just discovered the joy of pyopengl for 3D visualization. However the incantation I'm...
12
by: Tonino | last post by:
I have been looking through the previous posts - but with my lack of knowledge on the whole tkinter subject - I have no clue what to look for ... SO - can anyone please help with this ...? I...
2
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If...
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...
2
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and...
2
by: Kevin Walzer | last post by:
I'm porting a Tkinter application to wxPython and had a question about wxPython's event loop. The Tkinter app provides a GUI to a command-line tool. It gathers user input, and opens an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.