I have taken your code, and I could see a few errors with it. With some manipulation, I have managed to make it work. This is the result:
import Tkinter as tk
root = tk.Tk()
button3 = tk.Button(text="Quit", command=lambda: quit_program())
def quit_program():
root.destroy()
button3.pack()
root.mainloop()
Good luck!
Jordan.
----- EDIT -----
Sorry, I failed to read your question fully. Hopefully this will aid your endeavours.
I put Brian's code into a program, and I added the destroy function just as you said. I then added a button in the class StartPage
, in the function __init__
. It can be found here, with the name button3
.
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page",
font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Go to Page One",
command=lambda:
controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda:
controller.show_frame("PageTwo"))
button3 = tk.Button(self, text="Quit",
command=lambda:
controller.quit_program())
button1.pack()
button2.pack()
button3.pack()
My code ended up working perfectly, where when you press the button, it quits the program. I think you'll find that when you were calling on the quit_program
function, you were calling it like: controller.quitprogram
, where you should be adding in the parentheses after it, as it is a function, like: controller.quit_program()
. I haven't seen what you have actually put into your code, but in your question, you did not include the parentheses in your call.
Hope this helps!
Jordan.