newbie:this program stops responding after pressing quit button

Discussion in 'Python' started by Boris, Dec 4, 2007.

  1. Boris

    Boris Guest

    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( )
     
    Boris, Dec 4, 2007
    #1
    1. Advertising

  2. On Dec 4, 2007 8:32 AM, Boris <> wrote:
    > 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( )
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    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/
     
    Michael Speer, Dec 4, 2007
    #2
    1. Advertising

  3. Boris

    Eric Brunel Guest

    On Tue, 04 Dec 2007 14:32:34 +0100, Boris <> wrote:
    > 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
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
     
    Eric Brunel, Dec 4, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dotnet user
    Replies:
    0
    Views:
    346
    dotnet user
    Aug 22, 2005
  2. Replies:
    6
    Views:
    455
  3. elitehunter99
    Replies:
    0
    Views:
    457
    elitehunter99
    Oct 17, 2006
  4. Replies:
    1
    Views:
    140
    DJ Stunks
    Feb 1, 2006
  5. TM360
    Replies:
    2
    Views:
    212
    TM360
    Jun 30, 2005
Loading...

Share This Page