tkinter, sockets and threads together

Russell E. Owen no at spam.invalid
Thu Sep 11 22:27:58 CEST 2003

In article <79ad5955.0309111133.5f6bf26f at>,
 juliagoolia301 at (Julia Goolia) wrote:

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

More information about the Python-list mailing list