Tkinter programming problem
Andrew Gregory
andrew.gregory at npl.co.uk
Fri Aug 1 04:48:58 EDT 2003
Could someone help me out with these few lines of code: I would like
to know why the Quit button in this application removes the buttons
and causes "Quitting" to be printed, but does not close the outer
frame.
Andrew.
# Demonstration TK interface Windows application
# Runs ok from within IDLE
#
from Tkinter import *
class CommonStuff: # to get common access to variables and functions
def __init__(cself, frame):
cself.frame = frame
def say_hi(cself):
print "Hello all"
class MyWidgets(Frame, CommonStuff):
def __init__(wself, CS):
Frame.__init__(wself, CS.frame)
wself.quitbutton = Button(wself)
wself.quitbutton["text"] = "Quit"
wself.quitbutton["fg"] = "red"
wself.quitbutton["command"] = wself.destroy
wself.quitbutton.pack({"side": "left"})
wself.hi_there = Button(wself)
wself.hi_there["text"] = "Hello",
wself.hi_there["command"] = CS.say_hi
wself.hi_there.pack({"side": "left"})
class Application:
def __init__(self, master):
self.frame=Frame(master)
CS = CommonStuff(self.frame)
displayedwidget=MyWidgets(CS)
displayedwidget.grid(row=0, column=0)
self.frame.grid(row=0, column=0)
self.frame.columnconfigure(0)
displayedwidget.bind("<Destroy>", self.quit)
self.frame.update()
def quit(self, event):
print"Quitting..."
self.frame.destroy # Destroy frame and all children
root = Tk()
mainWin = Application(root)
root.wait_window(mainWin.frame)
More information about the Python-list
mailing list