我只是在學習python(有五天的時間來這樣做),而且我遇到了hello world程序的一些基本問題。任何想法,我缺少什麼?Hello World:應用程序實例沒有屬性'say_hi'
#!/user/bin/python3
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
def say_hi(self):
print "Hello word!"
self.button = Button (frame, text="QUIT",
fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi = Button (frame, text="Hello",
command=self.say_hi)
self.button.pack(side=RIGHT)
root = Tk()
app = App (root)
root.mainloop()
我得到的錯誤是:
File "HelloWorld.py", line 22, in <module>
app = App (root)
File "HelloWorld.py",
line 18, in __init__
command=self.say_hi)
AttributeError: App instance has no attribute 'say_hi'
不該def say_hi(self)
:創建實例?提前致謝。
這真的是你的縮進看起來如何? – zondo
編號def __init__後的所有內容都被正確縮進。將編輯上面的代碼。 – Mog