Strange terminal behavior after quitting Tkinter application

Chris ceball at gmail.com
Fri May 4 01:39:24 EDT 2007


(I apologize if some similar version of this message has already
appeared; I've tried several time to post it, seemingly without
success.)

>         If that is satisfactory, well and good. However, there
> is a possibility that you may lose some settings that you would
> prefer to keep. The terminal settings have been trashed, and
> stty sane has restored a minimally workable set, but some
> settings may not be what you expect.

I agree: I'll consider saving the terminal settings as you suggest.


>         Just in case, I did a google search. I am not familiar
> withTKinter, but a couple of articles out there imply
> that rather than calling sys.exit you should be calling aTkInterroutine root.destroy. I am not sure if root is a
> variable for the main window (ie you call the destroy method
> on the main window) or if it has some specialTkintermeaning.
> Presumably this routine cleans things up before calling sys.exit
> or an equivalent.

"root" is the name of a variable typically used by people to hold an
instance of Tkinter.Tk, the main application window (from
http://epydoc.sourceforge.net/stdlib/Tkinter.Tk-class.html: "Toplevel
widget of Tk which represents mostly the main window of an appliation.
It has an associated Tcl interpreter."). Instead of subclassing
Tkinter.Tk and instantiating that subclass for my application, I could
create a Tk instance and withdraw() it, then use a Toplevel. In my
example code above, I could call any 'root' methods on an instance of
my Application class, presumably with the same effect.

In any case, that might not be important - I think the problem comes
from not calling mainloop():

<code>
import Tkinter
import sys

root = Tkinter.Tk()
Tkinter.Button(root,text="Quit",command=sys.exit).pack()
root.mainloop()
</code>


Clicking 'Quit' or on the window's 'x' causes the application to quit
without messing up the terminal. With root.mainloop() commented out,
though, no combination of root.quit(), root.destroy(), and sys.exit()
stops the terminal from getting messed up.

So, I should call mainloop() for my application...except that I want
to use the commandline, too, and calling mainloop() freezes the
commandline. I wonder if there is another way to use the commandline
and have a GUI? I couldn't find any clear information about that.


Thanks again,
Chris




More information about the Python-list mailing list