Jul-20-2018, 09:03 AM
You need to provide a quit method:
I also moved the __init__ routine to top (will work elsewhere, but other programmers will always look for it at the top)
added startup code 'if __name__ ...'
and created class variable for delete
from tkinter import * class Application(Frame): def __init__(self, master=None): self.master = master self.master.geometry('300x100+10+10') Frame.__init__(self, master) self.pack() self.createWidgets() def new_button(self): print("enable_b") self.hi_there.config(state=ACTIVE) self.new_button.grid_remove() def say_hi(self): print("hi there, everyone!") self.new_button = Button(self) self.new_button["text"] = "New BTN" self.new_button.grid(row=1,column=0) self.hi_there.config(state=DISABLED, command=self.new_button) def createWidgets(self): self.QUIT = Button(self) self.QUIT.config(text="QUIT",fg="red",command=self.quit) self.QUIT.grid(row=0,column=1) self.hi_there = Button(self) self.hi_there["text"] = "Hello", self.hi_there["command"] = self.say_hi self.hi_there.grid(row=0,column=0) def quit(self): self.master.destroy() def testit(): root = Tk() app = Application(master=root) app.mainloop() if __name__ == '__main__': testit()
I also moved the __init__ routine to top (will work elsewhere, but other programmers will always look for it at the top)
added startup code 'if __name__ ...'
and created class variable for delete