from __future__ import print_function # # Create a GUI with a text entry field. # try: import Tkinter except ImportError: import tkinter as Tkinter # We use the same pattern as tkinter_label_entry.py def main(): app = Tkinter.Frame() app.grid() make_ui(app) app.mainloop() # "make_ui" is similar to the one in tkinter_label_entry.py. # Here, instead of arranging the four widgets into a 2x2 # grid, we create two rows: "f1" and "f2", with "f1" on # top of "f2". The label and entry widgets are in f1 and # the two buttons are in f2. Note that when you run the # program, the two buttons are now evenly spaced, because # the column widths in f1 are different than those in f2. # # We also changed the callback function "echo_cb". Instead # of printing the contents of the entry widget to standard # output, we reconfigure the label widget so that its text # matches the entry widget. Almost all attributes, eg # background color, text color, font, etc of all widgets # may be altered using their "config" method. def make_ui(app): def quit_cb(app=app): app.quit() f1 = Tkinter.Frame(app) f1.grid(row=0, column=0, sticky="nsew") label = Tkinter.Label(f1, text="Prompt") label.grid(row=0, column=0) entry = Tkinter.Entry(f1) entry.grid(row=0, column=1) def echo_cb(entry=entry, label=label): label.config(text=entry.get()) f2 = Tkinter.Frame(app) f2.grid(row=1, column=0, sticky="nsew") button = Tkinter.Button(f2, text="Echo", command=echo_cb) button.grid(row=0, column=0) button = Tkinter.Button(f2, text="Quit", command=quit_cb) button.grid(row=0, column=1) if __name__ == "__main__": main() print("Finished")