newbie:this program stops responding after pressing quit button

B

Boris

I am using windows vista and python 2.5 .This program stops responding
after pressing quit button. I am not able to figure the problem out.
please help.

from Tkinter import *

def greeting( ):
print 'Hello stdout world!...'

win = Frame(
)
win.pack( )
Label(win, text='Hello container world').pack(side=TOP)
Button(win, text='Hello', command=greeting).pack(side=LEFT)
Button(win, text='Quit', command=win.quit).pack(side=RIGHT)

win.mainloop( )
 
M

Michael Speer

I am using windows vista and python 2.5 .This program stops responding
after pressing quit button. I am not able to figure the problem out.
please help.

from Tkinter import *

def greeting( ):
print 'Hello stdout world!...'

win = Frame(
)
win.pack( )
Label(win, text='Hello container world').pack(side=TOP)
Button(win, text='Hello', command=greeting).pack(side=LEFT)
Button(win, text='Quit', command=win.quit).pack(side=RIGHT)

win.mainloop( )

While unfamiliar with the package, I loaded it up to see if I could
help you out.

I loaded Tkinter and ran your code under ubuntu in the interactive
prompt and saw the same result.

The doc for the win.quit function states "Quit the Tcl interpreter.
All widgets will be destroyed." but I certainly don't see that
happening here. If you really want to quit, try setting the command
for the quit button to sys.exit perhaps? This left my terminal in a
state I had to `reset` out of but it did kill the program.

Hmm. Further testing seems to show that it may be a simple matter of
Tkinter only getting rid of windows and things if there are no
references left to them from the python runtime.

Your win.quit won't destroy the window as long as the variable win refers to it.

Load up your interpreter and play with it interactively. Remember the
dir( object ) command will give a full listing of the attributes of
any given object. Looking at object.__doc__ will give you the
documentation. There's probably something in there to hide the window
if that is all you want.

Good luck solving your problem.

Michael Speer
http://michaelspeer.blogspot.com/
 
E

Eric Brunel

I am using windows vista and python 2.5 .This program stops responding
after pressing quit button. I am not able to figure the problem out.
please help.

from Tkinter import *

def greeting( ):
print 'Hello stdout world!...'

win = Frame(
)
win.pack( )

While I can't reproduce the problem you have since I'm on an older
Python/Tkinter version, I'd say these last two lines are the problem: in
Tkinter, Frame instances are not windows, but generic containers. Creating
a Frame instance without having a window implicitly creates one, but you
have to use some Tkinter internals to manipulate it, which is never a good
idea. I'd replace these two lines with this one:

win = Tk()

which actually create the main window for the application as well as the
underlying tcl interpreter, required by Tkinter.

Please note this must be done only for the main window, i.e exactly once
in your application; other ones must be created as Toplevel instances, not
Tk ones.
Label(win, text='Hello container world').pack(side=TOP)
Button(win, text='Hello', command=greeting).pack(side=LEFT)
Button(win, text='Quit', command=win.quit).pack(side=RIGHT)

win.mainloop( )

HTH
 

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,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top