FAQ
Studying 'Graphs & Charts' in 'Python and Tkinter Programming'
(pg 276 ff) and it looks to me like the code below should:

(a) put a window on screen with a Quit button under
400x400 canvas

(b) quit that window when Quit button is pressed

drawgraph() is in a module, and I'm launching it from
IDLE, going:
import tkgraph
tkgraph.drawgraph()
So the window pops up. When I hit Quit, I get the
prompt back:

>>>

in the IDLE Window, but the 400x400 canvas is still
topmost -- didn't go away. I have to hit the close
box (X in upper right corner) to kill the Window.

This doesn't seem to be the behavior documented in
Tkinter class, which says quit method will cause all
widgets to be destroyed.

Whether documented or not, my question is, how to I
make the Quit button both return to IDLE _and_
get rid of the window.

============================
# simple graphing -- tkgraph.py

# doesn't actually graph anything yet -- just testing
# window behavior

from Tkinter import *

def drawgraph():
root = Tk()
canvas = Canvas(root,height@0,width@0, bg='white')
canvas.pack()
Button(root,text='Quit',command=root.quit).pack()
root.mainloop()

Search Discussions

  • Kirby Urner at Sep 21, 2000 at 3:59 pm

    Kirby Urner wrote:
    This doesn't seem to be the behavior documented in
    Tkinter class, which says quit method will cause all
    widgets to be destroyed.
    I should add that pressing the Quit button a second
    time (after getting the IDLE prompt back on the first),
    closes IDLE/Python altogether.

    I'm thinking this behavior (of command=root.quit not
    closing the window) has to do with starting Tk.mainloop()
    from within IDLE (itself a Tk application). Given IDLE
    is where I'd like younger school students to operate,
    having a 'Quit' button that closes the window (doesn't
    stick around inviting a 2nd click) is the behavior I
    need.

    Kirby
    ============================>
    # simple graphing -- tkgraph.py

    # doesn't actually graph anything yet -- just testing
    # window behavior

    from Tkinter import *

    def drawgraph():
    root = Tk()
    canvas = Canvas(root,height@0,width@0, bg='white')
    canvas.pack()
    Button(root,text='Quit',command=root.quit).pack()
    root.mainloop()
  • Kirby Urner at Sep 21, 2000 at 4:25 pm
    Kirby Urner wrote:

    Here's a workaround that gets me the behavior I want, i.e.
    hitting Quit both returns to IDLE _and_ kills the window.

    # simple graphing

    from Tkinter import *

    class graph:

    def __init__(self):
    self.root = ""

    def drawgraph(self):
    self.root = Tk()
    canvas = Canvas(self.root,height@0,width@0, bg='white')
    canvas.pack()
    Button(self.root,text='Quit',command=self.quit).pack()
    self.root.mainloop()

    def quit(self):
    self.root.quit()
    self.root.destroy()

    Kirby

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 21, '00 at 3:43a
activeSep 21, '00 at 4:25p
posts3
users1
websitepython.org

1 user in discussion

Kirby Urner: 3 posts

People

Translate

site design / logo © 2022 Grokbase