Newbie Tkinter: how to quit window? (Win98, IDLE, Python 2.0b)
Kirby Urner
urner at alumni.princeton.edu
Wed Sep 20 23:43:38 EDT 2000
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=400,width=400, bg='white')
canvas.pack()
Button(root,text='Quit',command=root.quit).pack()
root.mainloop()
More information about the Python-list
mailing list