469,964 Members | 1,772 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Strange terminal behavior after quitting Tkinter application

Hi,

I'm puzzled by some strange behavior when my Python/Tkinter
application quits (on linux): the terminal from which I started Python
is messed up.

If start up python, then import the code below, then start the program
with Application(), then click the Quit button, my terminal never
prints anything again (such as commands I type).

<code>

import Tkinter
import sys

class Application(Tkinter.Tk):

def __init__(self,**config):
Tkinter.Tk.__init__(self,**config)

Tkinter.Button(self,text="Quit",command=self.quit_ application).pack()

def quit_application(self):
sys.exit()

</code>
Can anyone tell me what I'm doing wrong?

Thanks for your help.

Chris

Apr 18 '07 #1
4 1941
(I'm not sure what happened to the formatting in my post: the
"Tkinter.Button" line should be at the same level of indentation as
the "Tkinter.Tk.__init__" line.)

Apr 18 '07 #2

On Apr 18, 2007, at 2:33 AM, Chris wrote:
>
I'm puzzled by some strange behavior when my Python/Tkinter
application quits (on linux): the terminal from which I started Python
is messed up.

If start up python, then import the code below, then start the program
with Application(), then click the Quit button, my terminal never
prints anything again (such as commands I type).

<code>

import Tkinter
import sys

class Application(Tkinter.Tk):

def __init__(self,**config):
Tkinter.Tk.__init__(self,**config)

Tkinter.Button(self,text="Quit",command=self.quit_ application).pack()

def quit_application(self):
sys.exit()

</code>
Can anyone tell me what I'm doing wrong?
What happens if you type 'stty sane' (and of course, a carriage
return) afterwards?
Apr 18 '07 #3
What happens if you type 'stty sane' (and of course, a carriage
return) afterwards?
The terminal returns to normal, thanks!

But does anyone know why the Tkinter program is doing this to the
terminal in the first place? I don't want to have to tell users of my
program that they must recover their terminal's sanity each time after
running my program.

Apr 18 '07 #4
Chris wrote:
>
But does anyone know why the Tkinter program is doing this to the
terminal in the first place? I don't want to have to tell users of my
program that they must recover their terminal's sanity each time after
running my program.
I don't know about Tkinter, but my guess would be that
it has to change the terminal settings to do what it does, and
you are quitting without restoring the settings.

Is there some Tkinter clean up that you have omitted ?

Have you ensured that the clean up runs on both normal
exit and abnormal exit (eg ^C) ?

For example, the curses library (in C) requires an
endwin() call before exit to restore settings. If this
is omitted, a "stty sane" is needed to set the terminal to
a semi-sensible default. On Unix and similar systems, signal
handlers are normally installed to ensure (as far as possible)
that the cleanup occurs if the process is killed. This also
applies to vi and similar programs that take total control of
the terminal.
Charles
Apr 19 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by srijit | last post: by
8 posts views Thread by bearophileHUGS | last post: by
14 posts views Thread by mystilleef | last post: by
3 posts views Thread by AinO | last post: by
1 post views Thread by mwolf | last post: by
6 posts views Thread by Peter Kleiweg | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.