from __future__ import print_function try: import Tkinter except ImportError: import tkinter as Tkinter # # Create a GUI with a text widget whose items may be edited # as well as controlled by buttons. # class TextDemo: # __init__() and run() together serve the same # purpose as the main() function in other examples. def __init__(self): self.app = Tkinter.Frame() self.app.grid(sticky="nsew") self.make_ui(self.app) # We have to tell the toplevel window that the frame # that we created should be adjustable (weight != 0) top = self.app.winfo_toplevel() top.columnconfigure(0, weight=1) top.rowconfigure(0, weight=1) def run(self): self.app.mainloop() # "make_ui" is similar to the one in tkinter_canvas.py # except we call "make_movable" for each item we create. def make_ui(self, app): self.text = Tkinter.Text(app, width=80, height=40) # Just as above, we need to tell "app" that the widget # in row 0, column 0 is resizable app.columnconfigure(0, weight=1) app.rowconfigure(0, weight=1) self.text.grid(row=0, column=0, sticky="nsew") # Create a frame to hold buttons across bottom f = Tkinter.Frame(app) f.grid(row=1, column=0, sticky="ew") b = Tkinter.Button(f, text="Clear", command=self.clear_cb) b.grid(row=0, column=0) b = Tkinter.Button(f, text="Mark", command=self.mark_cb) b.grid(row=0, column=1) b = Tkinter.Button(f, text="Quit", command=app.quit) b.grid(row=0, column=2) def clear_cb(self): self.text.delete("1.0", "end") def mark_cb(self): self.text.insert("end", "\n--- MARK ---\n") if __name__ == "__main__": TextDemo().run() print("Finished")