FAQ
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('WM_DELETE_WINDOW', lambda:0) # ignore close
win.iconbitmap('py-blue-trans-out.ico') # not red Tk

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

root.title('Lumberjack demo')
Label(root, text='Main window', width0).pack()
#Button(root, text='Quit All', command=root.quit).pack() # kills
all app
Button(root, text='Quit All', command=root.destroy).pack() # kills all
app
root.mainloop()

Search Discussions

  • Fredrik Lundh at Oct 12, 2006 at 6:55 pm

    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>
  • Mzdude at Oct 13, 2006 at 12:48 am
    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.



    From http Fri Oct 13 02:54:25 2006
    From: http (Paul Rubin)
    Date: 12 Oct 2006 17:54:25 -0700
    Subject: Standard Forth versus Python: a case study
    References: <oMSdnejEoa3By7DYnZ2dnUVZ_v2dnZ2d@wispertel.com>
    <7x3b9u376m.fsf@ruckus.brouhaha.com>
    <Z46dnTJWqdH0wLDYnZ2dnUVZ_sOdnZ2d@wispertel.com>
    <1160603937.392188.253250@m7g2000cwm.googlegroups.com>
    <1160619958.438049.53390@h48g2000cwc.googlegroups.com>
    <l2jXg.63366$5o5.46778@tornado.texas.rr.com>
    <1160652722.908731.213650@i42g2000cwa.googlegroups.com>
    <7xfydtojhe.fsf@ruckus.brouhaha.com>
    <7x4pu9bw3z.fsf@ruckus.brouhaha.com>
    <1160685854.118420.133080@e3g2000cwe.googlegroups.com>
    <mailman.408.1160699034.11739.python-list@python.org>
    Message-ID: <7xmz81m3we.fsf@ruckus.brouhaha.com>

    Gabriel Genellina <gagsl-py at yahoo.com.ar> writes:
    That explains all. Finding the median in an efficient way (that is,
    without sorting the data first) isn't trivial, so your claim of "I can
    do that using only one temp variable" was a bit surprising...
    BTW, the median is the value which sits just in the middle of the list
    when ordered: median(3,5,12,1,2)=median(1,2,3,5,12) = 3
    How is this? Note that m and n are treated as constants, so
    expressions like n-1, n/2 etc. are also constants. Also assume
    m[i+1] is evaluated as (m+1)[i] and of course m+1 is constant.

    ================================================================

    #include <stdio.h>

    int
    median (int m[], int n)
    {
    int i;
    while (1) {
    for (i = 0; i < n-1; i++) {
    if (m[i] > m[i+1]) {
    /* swap m[i] and m[i+1] with no temp var */
    m[i] ^= m[i+1];
    m[i+1] ^= m[i];
    m[i] ^= m[i+1];
    goto yes;
    }
    }
    break;
    yes:
    for (i = 0; i < n-1; i++) {
    if (m[i] > m[i+1]) {
    m[i] ^= m[i+1];
    m[i+1] ^= m[i];
    m[i] ^= m[i+1];
    }
    }
    }
    return m[n / 2];
    }

    int a[] = {9,6,1,5,4,2,8,3,7};

    main()
    {
    int m;
    m = median(a, 9);
    printf ("%d\n", m);
    }
  • Neil Cerutti at Oct 13, 2006 at 12:40 pm

    On 2006-10-13, mzdude 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
  • Fredrik Lundh at Oct 13, 2006 at 4:09 pm

    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>
  • Mzdude at Oct 13, 2006 at 5:54 pm

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 12, '06 at 5:58p
activeOct 13, '06 at 5:54p
posts6
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase