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.quitbutto n = Button(wself)
wself.quitbutto n["text"] = "Quit"
wself.quitbutto n["fg"] = "red"
wself.quitbutto n["command"] = wself.destroy
wself.quitbutto n.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=Fram e(master)
CS = CommonStuff(sel f.frame)
displayedwidget =MyWidgets(CS)
displayedwidget .grid(row=0, column=0)
self.frame.grid (row=0, column=0)
self.frame.colu mnconfigure(0)
displayedwidget .bind("<Destroy >", self.quit)
self.frame.upda te()
def quit(self, event):
print"Quitting. .."
self.frame.dest roy # Destroy frame and all children
root = Tk()
mainWin = Application(roo t)
root.wait_windo w(mainWin.frame )
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.quitbutto n = Button(wself)
wself.quitbutto n["text"] = "Quit"
wself.quitbutto n["fg"] = "red"
wself.quitbutto n["command"] = wself.destroy
wself.quitbutto n.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=Fram e(master)
CS = CommonStuff(sel f.frame)
displayedwidget =MyWidgets(CS)
displayedwidget .grid(row=0, column=0)
self.frame.grid (row=0, column=0)
self.frame.colu mnconfigure(0)
displayedwidget .bind("<Destroy >", self.quit)
self.frame.upda te()
def quit(self, event):
print"Quitting. .."
self.frame.dest roy # Destroy frame and all children
root = Tk()
mainWin = Application(roo t)
root.wait_windo w(mainWin.frame )
Comment