From: Andrew Svetlov Date: Thu, 15 Mar 2012 04:41:23 +0000 (-0700) Subject: Closes issue #14163 - tkinter: problems with hello doc example X-Git-Tag: v3.3.0a2~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3d7c903e6ee86d54d7fdb720ce81f24ee75e316;p=python Closes issue #14163 - tkinter: problems with hello doc example --- diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index ae5635f3c8..62eedff7d7 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