Appropriate way to quit Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mzdude

    #1

    Appropriate way to quit Tkinter

    I've just started playing with Python. Installed 2.5 on Windows XP
    system. I'm working through some of the examples in Programming Python
    3ed by Mark Lutz. Given the following example when the Quit All button
    action is assigned to root.quit the windows aren't dismissed or
    destroyed. The application appears to terminate, but the windows
    remain. When the action is assigned to root.destroy, the windows are
    closed. Questions:
    1) Which way is preferred / correct?
    2) Is something wrong with 2.5? (I haven't tried older versions of
    python)
    3) Is there something wrong with my installation?


    ############### ############### ############### ############### ############### ##
    # popup three new window, with style
    # destroy() kills one window, quit() kills all windows and app;
    top-level
    # windows have title, icon, iconify/deiconify and protocol for wm
    events;
    # there always is an app root window, whether by default or created as
    an
    # explicit Tk() object; all top-level windows are containers, but never

    # packed/gridded; Toplevel is like frame, but new window, and can have
    menu;
    ############### ############### ############### ############### ############### ##

    from Tkinter import *
    root = Tk() # explicit root

    trees = [('The Larch!', 'light blue'),
    ('The Pine!', 'light green'),
    ('The Giant Redwood!', 'red')]

    for (tree, color) in trees:
    win = Toplevel(root)
    # new window
    win.title('Sing ...')
    # set border
    win.protocol('W M_DELETE_WINDOW ', lambda:0) # ignore close
    win.iconbitmap( 'py-blue-trans-out.ico') # not red Tk

    msg = Button(win, text=tree, command=win.des troy) # kills one win
    msg.pack(expand =YES, fill=BOTH)
    msg.config(padx =10, pady=10, bd=10, relief=RAISED)
    msg.config(bg=' black', fg=color, font=('times', 30, 'bold italic'))

    root.title('Lum berjack demo')
    Label(root, text='Main window', width=30).pack( )
    #Button(root, text='Quit All', command=root.qu it).pack() # kills
    all app
    Button(root, text='Quit All', command=root.de stroy).pack() # kills all
    app
    root.mainloop()

  • Fredrik Lundh

    #2
    Re: Appropriate way to quit Tkinter

    mzdude wrote:
    I've just started playing with Python. Installed 2.5 on Windows XP
    system. I'm working through some of the examples in Programming Python
    3ed by Mark Lutz. Given the following example when the Quit All button
    action is assigned to root.quit the windows aren't dismissed or
    destroyed. The application appears to terminate, but the windows
    remain. When the action is assigned to root.destroy, the windows are
    closed. Questions:
    1) Which way is preferred / correct?
    quit() causes the mainloop() call to return. if calling mainloop() is
    the last thing you do in your program, the program terminates.

    destroy() destroys the given window. if that's the last window, the
    mainloop() is terminated as well.
    2) Is something wrong with 2.5? (I haven't tried older versions of
    python)
    not that I can see.
    3) Is there something wrong with my installation?
    works for me. are you perhaps running this under some kind of IDE that
    keeps the process running even after the program has terminated?

    </F>

    Comment

    • mzdude

      #3
      Re: Appropriate way to quit Tkinter


      Fredrik Lundh wrote:
      [snip]
      works for me. are you perhaps running this under some kind of IDE that
      keeps the process running even after the program has terminated?
      >
      It works the same way if I run from IDLE or from the DOS command prompt.

      Comment

      • Neil Cerutti

        #4
        Re: Appropriate way to quit Tkinter

        On 2006-10-13, mzdude <jsanga@cox.net wrote:
        >
        Fredrik Lundh wrote:
        [snip]
        >works for me. are you perhaps running this under some kind of
        >IDE that keeps the process running even after the program has
        >terminated?
        >
        It works the same way if I run from IDLE or from the DOS
        command prompt.
        I had some fun trying to run Tkinter from from the Python
        embedded in Vim. My advice: Do not do that.

        --
        Neil Cerutti
        The majority of time, it seems to be one thing or the other.
        --Ron Mercer

        Comment

        • Fredrik Lundh

          #5
          Re: Appropriate way to quit Tkinter

          mzdude wrote:
          >works for me. are you perhaps running this under some kind of IDE that
          >keeps the process running even after the program has terminated?
          >>
          It works the same way if I run from IDLE or from the DOS command prompt.
          I find very hard to believe that a Python interpreter run from the DOS
          command prompt wouldn't terminate when it reaches the end of the main
          program.

          what Python distribution are you using?

          </F>

          Comment

          • mzdude

            #6
            Re: Appropriate way to quit Tkinter


            Fredrik Lundh wrote:
            mzdude wrote:
            >
            works for me. are you perhaps running this under some kind of IDE that
            keeps the process running even after the program has terminated?
            >
            It works the same way if I run from IDLE or from the DOS command prompt.
            >
            I find very hard to believe that a Python interpreter run from the DOS
            command prompt wouldn't terminate when it reaches the end of the main
            program.
            >
            what Python distribution are you using?
            >
            </F>
            Not sure I understand the question. I downloaded python-2.5.msi from
            python.org/download.
            >From the IDLE
            Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
            (Intel)] on win32
            Type "copyright" , "credits" or "license()" for more information.

            Comment

            Working...