CLI+GUI

smarter_than_you davesum99 at yahoo.com
Wed Aug 13 09:03:43 EDT 2003


mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308121335.7f1ad18a at posting.google.com>...
> danbmil99 at yahoo.com (dan) wrote in message news:<fbf8d8f2.0308120814.75e8dff at posting.google.com>...
> > 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
> 
> I like quite a lot you suggestion! "dooneevent" was the method I was
> looking for! Actually, I would rather prefer to avoid threads for such a
> simple program. Thanks to the power of Python I wrote down a working
> script in less than five minutes, even if probably I will need more
> than five minutes to understand what I wrote ;)
> Here it is:
> 
> import Tkinter as t
> import cmd
> 
> root=t.Tk()
> s=t.StringVar()
> s.set('ciao')
> label=t.Label(root,textvariable=s)
> label.pack()
> 
> class Cmd(cmd.Cmd):
>     def do_display(self,arg):
>         s.set(arg)
>         root.tk.dooneevent(0)
>     def do_quit(self,arg):
>         root.quit()
>         return 'quit' # anything != None will do
> 
> Cmd().cmdloop()
> 
> 
> I will later try it on Windows 98. Dunno exactly what "dooneevent" is doing,
> I searched my python directories for "dooneevent" and found only one
> usage of "doonevent" and copied it ;) Unfortunately "dooneevent" 
> has no docstring, however few experiments show that "dooneevent()" 
> is the same that "dooneevent(0)" whereas "dooneevent(1)" hangs up 
> (it is waiting for what??)
> 
the problem is that most of the documentation is in TK/TCL itself. 
TKinter is just a wrapper.  There are some docs on how the stuff is
wrapped, then you have to go to Tk/tcl docs to get the real info.

My best guess is that it's a wrapper to this call:

http://www.tcl.tk/man/tcl8.4/TclLib/DoOneEvent.htm

note the confusion because it's really a tcl call, but Tkinter doesn't
make a distinction between tk & tcl.

Also note that there are at least three ways to get this behavior:

_tkinter.dooneevent(TCL_DONT_WAIT)
Frame.update()
Tkinter.dooneevent(0) #this is new to me!  You found a third way to
call it

it's all a bit mysterious, but basically you're calling the event
handler within TK's mainloop.

best - dan




More information about the Python-list mailing list