from __future__ import print_function # # Create a GUI with a single button that causes # the event loop to terminate. # try: import Tkinter except ImportError: import tkinter as Tkinter # Once again, our main application frame app = Tkinter.Frame() app.grid() # This is the callback that will be invoked when the # button is pushed. def quit_cb(app=app): app.quit() # This time, we add a "command" argument whose value # is the function to call when the button is pressed. # Note that we never call "quit_cb" directly from our # code; we depend on Tkinter to call it at the # appropriate time. button = Tkinter.Button(app, text="Quit", command=quit_cb) button.grid(row=0, column=0) # Again, enter the event loop and wait for it to end. app.mainloop() print("Finished")