By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

Running user scripts in a Tkinter app?

P: n/a
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()

def waitcmd(cmd_obj):
while not cmd_obj.isdone():
tkobj.update()

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?

-- Russell
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.