diff options
-rw-r--r-- | Doc/library/tkinter.rst | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index ae5635f..62eedff 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -179,35 +179,30 @@ A Simple Hello World Program :: - from tkinter import * - - class Application(Frame): - def say_hi(self): - print("hi there, everyone!") - - def createWidgets(self): - self.QUIT = Button(self) - self.QUIT["text"] = "QUIT" - self.QUIT["fg"] = "red" - self.QUIT["command"] = self.quit - - self.QUIT.pack({"side": "left"}) - - self.hi_there = Button(self) - self.hi_there["text"] = "Hello", - self.hi_there["command"] = self.say_hi - - self.hi_there.pack({"side": "left"}) - - def __init__(self, master=None): - Frame.__init__(self, master) - self.pack() - self.createWidgets() - - root = Tk() - app = Application(master=root) - app.mainloop() - root.destroy() + import tkinter as tk + + class Application(tk.Frame): + def __init__(self, master=None): + tk.Frame.__init__(self, master) + self.pack() + self.createWidgets() + + def createWidgets(self): + self.hi_there = tk.Button(self) + self.hi_there["text"] = "Hello World\n(click me)" + self.hi_there["command"] = self.say_hi + self.hi_there.pack(side="top") + + self.QUIT = tk.Button(self, text = "QUIT", fg = "red", + command = root.destroy) + self.QUIT.pack(side = "bottom") + + def say_hi(self): + print("hi there, everyone!") + + root = tk.Tk() + app = Application(master=root) + app.mainloop() A (Very) Quick Look at Tcl/Tk |