Tkinter programming problem
Andrew Gregory
andrew.gregory at npl.co.uk
Mon Aug 4 06:01:53 EDT 2003
Many thanks for such a comprehensive answer.
Altered root.wait_window(mainWin.frame) to root.mainloop()
and found that it runs and closes ok within IDLE. I seem to remember
having crashes on closing within IDLE before.
I did try self.frame.destroy as the function
self.frame.destroy(), but the Quit button still didn't work. The
application can be closed via the window corner X, but I'm still
puzzled as to why it does not respond to Quit.
Any more suggestions?
Updated code below, 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__(self, frame):
self.frame = frame
def say_hi(self):
print "Hello all"
class MyWidgets(Frame, CommonStuff):
def __init__(self, CS):
Frame.__init__(self, CS.frame)
self.quitbutton = Button(self, text='Quit', fg='red',
command=self.destroy)
self.quitbutton.pack(side=LEFT)
self.hi_there = Button(self, text='Hello', command=CS.say_hi)
self.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)
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.mainloop()
More information about the Python-list
mailing list