Suggestions on sockets and Tkinter

Jonathan Giddy jon at bezek.dstc.monash.edu.au
Tue Oct 24 20:17:25 EDT 2000


T Teemu E Kurppa <ttkurppa at cs.Helsinki.FI> writes:

] Main purpose of simulator is to simulate the game, NOT to view it. So it
] should read sockets frequently and update it state, and now and then
] (approx. 10 times in second ...) also update the graphical view. 
] However, in Tkinter programming, I must enter to Tkinter's mainloop, and
] can not run my own. Now, I can use after command or createfilehandler to
] get events for handling the sockets, but for my needs this solution will
] turn the situation wrong-side-up.
 
I can think of 3 ways to handle this:

1. Use threads, one thread handles sockets, the other calls mainloop().
Works OK on Unix, I believe not so well on Windows, although there are
ways around it.

2. Use the Tcl interpreter that is builtin to Python when Tk is enabled.
This would require using the _tkinter functions, particularly the call 
function for any Tcl commands that are not supported directly.  Yuk!

3. The _tkinter module provides access to the Tcl_DoOneEvent interface.
At appropriate times, you can call this to let Tkinter run.  
TCL_DONT_WAIT = (1<<1)  # From tcl.h
while _tkinter.dooneevent(TCL_DONT_WAIT):
    pass  # empty the Tk event queue





More information about the Python-list mailing list