from __future__ import print_function # # Create a GUI with a single push button # try: import Tkinter except ImportError: import tkinter as Tkinter # I like having a Frame object as the top-level GUI # "application" element that contains everything else. # Since I don't give Frame any arguments, it gets # placed in a window all by itself. app = Tkinter.Frame() # Grid is part of "geometry management". The three # most commonly used arguments are "row", "column" # and "sticky". As implied by the name, grid places # widgets in a grid. "row" and "column" specify the # position in the grid. "sticky" specifies which side # of the widget is "attached" to the container frame. # In this case, "nsew" means "north", "south", "east" # and "west", so all four sides of "app" are sticking # to the container (which happens to be the GUI window). # If the window is resized, then "app" will get resized # as well. app.grid(row=0, column=0) # Now we create a button inside our "app" frame, as # specified by the first argument. "app" is called the # "parent" widget of "button"; and "button" is called # a "child" widget of "app". The label in the button # is specified in the "text" argument. button = Tkinter.Button(app, text="Click me") # We need to specify where "button" is placed relative # to "app". In this case, we put it in row 0, column 0. # Tkinter is pretty smart about grid positioning, so # things that look like they should work usually do. button.grid(row=0, column=0) # Finally, we enter the GUI event loop. app.mainloop() # We get here when the event loop terminates, eg when # the window is closed. print("Finished")