eric.brunel at pragmadev.com
Mon Aug 11 09:58:02 CEST 2003
Michele Simionato wrote:
> mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308080948.5a95e383 at posting.google.com>...
>>I wonder what is the recommended way of using Tkinter
>>together with a command line oriented application.
> Replying to myself ...
> I tried to implement what I discussed in my previous mail via the
> threading module:
> import Tkinter as t
> import cmd,threading
> class Cmd(cmd.Cmd):
> def do_display(self,arg):
> def do_quit(self,arg):
> return 'quit' # anything <> None will do the job
> def cmdloop(stringvar):
> try: Cmd().cmdloop()
> finally: pass # gracefully exit if sometimes goes wrong
> It works if I do something like
> $ python cmdriven.py
> (Cmd) display hello
> (Cmd) display It works!
> (Cmd) quit
> However, I wonder if this is a robust solution and if I should expect
> problems in more complicate situations (some time passes ... I have
> just discovered that this script hangs under Windows 98!)
I don't know if this is the problem, because you didn't say exactly when the
script hangs, but Tkinter apparently has problems when calls to it are made from
a thread different from the one into which it was initialized. I'd use an Event
between Tkinter's thread and Cmd's thread, checking it regularly with Tkinter's
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list