CLI+GUI

dan danbmil99 at yahoo.com
Tue Aug 12 12:14:49 EDT 2003


Late to this thread, but --

in a similar situation, I just put:

  _tkinter.dooneevent(_tkinter.DONT_WAIT)

in my main logic loop (cmd interpreter in your case), instead of
calling Frame.mainloop().  I believe Frame.update() does something
similar but for some reason this worked better.

ISTM this would be cleaner (and safer) than using threads.  You can do
all your draw operations from your command line routines, and they
will get displayed as soon as the routine returns to your main loop to
wait for more input.

Am I missing something?

-dbm

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. 
> I have in mind something like that:
> 
> import cmd,sys
> 
> class CMD(cmd.Cmd):
>     def do_this(self,*args):
>         draw_a_diagram()
>     def do_that(self,*args):
>         draw_another_diagram()
>     def do_exit(self,*args):
>         sys.exit(0)
> 
> c=CMD()
> c.cmdloop()
> 
> Here the methods ``draw_a_diagram`` and ``draw_another_diagram``
> should do what you expect.  Notice that I don't want to use
> different windows, the graphs should be displayed on the same
> window one over the other. BTW, I am not really displaying
> diagrams, this is only the simplest example I can figure out
> of graphics program driven by a command line interpreter.
> I want to stay with the CLI interface, which I like a lot 
> thanks to the readline and completion support, the easy
> of use and the easy of implementation.
> 
> I have no idea of how to do that, except via contorsions
> such as saving (a representation of) the diagrams in a file 
> and having a separated Tkinter process that periodically look at the
> file, changing the display if the file has been updated. I
> guess there is a better way, since this is a quite common issue.
> Any suggestion?
> 
> TIA,
> 
>                  Michele




More information about the Python-list mailing list