Closes issue #14163 - tkinter: problems with hello doc example

This commit is contained in:
Andrew Svetlov 2012-03-14 21:41:23 -07:00
parent 7b51b8de38
commit d3d7c903e6

View file

@ -179,35 +179,30 @@ A Simple Hello World Program
:: ::
from tkinter import * import tkinter as tk
class Application(Frame): class Application(tk.Frame):
def say_hi(self): def __init__(self, master=None):
print("hi there, everyone!") tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self): def createWidgets(self):
self.QUIT = Button(self) self.hi_there = tk.Button(self)
self.QUIT["text"] = "QUIT" self.hi_there["text"] = "Hello World\n(click me)"
self.QUIT["fg"] = "red" self.hi_there["command"] = self.say_hi
self.QUIT["command"] = self.quit self.hi_there.pack(side="top")
self.QUIT.pack({"side": "left"}) self.QUIT = tk.Button(self, text = "QUIT", fg = "red",
command = root.destroy)
self.QUIT.pack(side = "bottom")
self.hi_there = Button(self) def say_hi(self):
self.hi_there["text"] = "Hello", print("hi there, everyone!")
self.hi_there["command"] = self.say_hi
self.hi_there.pack({"side": "left"}) root = tk.Tk()
app = Application(master=root)
def __init__(self, master=None): app.mainloop()
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
A (Very) Quick Look at Tcl/Tk A (Very) Quick Look at Tcl/Tk