Running user scripts in a Tkinter app?

Discussion in 'Python' started by Russell E. Owen, Sep 10, 2003.

  1. 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
    Russell E. Owen, Sep 10, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    586
    Steve Holden
    Apr 30, 2005
  2. Jan Danielsson
    Replies:
    8
    Views:
    611
    Mike Meyer
    Jul 22, 2005
  3. Jp Calderone
    Replies:
    0
    Views:
    443
    Jp Calderone
    Jul 21, 2005
  4. Bernard Lebel
    Replies:
    8
    Views:
    439
    Mikael Olofsson
    May 31, 2006
  5. skinnybloke
    Replies:
    1
    Views:
    80
Loading...

Share This Page