Tkinter programming problem

Andrew Gregory andrew.gregory at
Mon Aug 4 12:01:53 CEST 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',
        self.hi_there = Button(self, text='Hello', command=CS.say_hi)

class Application:
    def __init__(self, master):
        CS = CommonStuff(self.frame)

        displayedwidget.grid(row=0, column=0)
        self.frame.grid(row=0, column=0)
        displayedwidget.bind("<Destroy>", self.quit)
    def quit(self, event):
        self.frame.destroy()  # Destroy frame and all children

root = Tk()
mainWin = Application(root)

More information about the Python-list mailing list