I have been writing a program for a GUI based plotter using matplotlib and tkinter. I have added a toplevel window for some options. I want to execute a function and quit the to
Buttons are designed for exactly this. Typically you would define a function or method that does whatever you want, then assign that method to the command
attribute of the button:
import Tkinter as tk
import tkMessageBox
class SampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
button = tk.Button(text="Press me!", command=self.on_button)
button.pack()
def on_button(self):
tkMessageBox.showinfo(message="Good-bye!")
self.destroy()
app = SampleApp()
app.mainloop()