Running user scripts in a Tkinter app?
Russell E. Owen
rowen at cesmail.net
Wed Sep 10 20:37:46 CEST 2003
I have a Python/Tkinter remote control application and want to add
support for running user scripts.
I would like the scripts to be written in python, would like them to be
able to update Tkinter widgets and (the hard part) would also like them
to be capable of pausing until some condition is met (e.g. a remote
control command finishes) without hanging the event loop.
I plan to add a library of routines to send commands and wait for
specific replies. For example:
- call(cmd) sends a command string to the remote host and returns a
"command object" that keeps track of the state of the command
- waitcmd(cmd_obj) pauses the script (but not the overall application)
until cmd_obj finishes or fails
I'm confused as to the best way to write the "waitcmd" function. It
seems like a good place to use threads, but my understanding is that
Tkinter is not thread safe.
The only solution I've thought of is to try to recreate the Tkinter main
loop within the wait function. Very crudely:
tkobj = Tkinter.Frame()
while not cmd_obj.isdone():
I think this will work, but am worried it will be much slower than the
usual Tkinter main event loop. If there was some way to start a new
Tkinter event loop (while the main loop is paused) and terminate this
new loop when the wait was finished, that'd be perfect.
Any suggestions? Would this be easier in some other GUI library?
More information about the Python-list