Re: More Tkinter questions

Guido.van.Rossum@cwi.nl
Tue, 07 Jun 1994 10:34:42 +0200

> I'm currently working on an application that will have a Tk
> interface and will require socket I/O at the same time. For
> simplicity, consider it a windowed version of the UNIX 'talk'
> program. The interface consists of a screen containing what is
> received over the socket.

> In telnet.py, socket I/O is handled via the UNIX fork command. This
> creates two processes, one reading and one writing. Now I need to
> interface this with Tk.

> Since socket.read() waits for input, I first added yet another
> process using fork. The problem: it apparently caused the creation
> of two separate widgets, one of which was displayed and was using
> mainloop(), the other of which was NOT being displayed and was used
> by the receiver process. In other words, trying to add received text
> to the Text widget didn't work.

I would use a single process and call select to figure out if there's
anything to read from the socket. I don't know tk well enough (yet)
to know if it has hooks for this, but you can always use 'after' to
have some Python function called frequently (e.g. every 10 msec).
Your Python code can then use select and decide to read from the
socket.

If it doesn't alraeady exists, it would be useful to add a hook for
this to the C interface to Tk...

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>