Strange terminal behavior after quitting Tkinter application

C

Chris

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
 
C

Chris

(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.)
 
M

Michael Bentley

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?
 
C

Chris

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.
 
C

Charles Sanders

Chris said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top