Running user scripts in a Tkinter app?

R

Russell E. Owen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top