需要一个简单python错误的帮助吗
我想做一个非常简单的程序。我已经做了一个类似的,它的工作。然而,这一个是给我的错误。代码中的第二个按钮是错误所指的地方。我不知道怎么了。我是编程新手。任何帮助都将不胜感激需要一个简单python错误的帮助吗,python,user-interface,tkinter,syntax-error,Python,User Interface,Tkinter,Syntax Error,我想做一个非常简单的程序。我已经做了一个类似的,它的工作。然而,这一个是给我的错误。代码中的第二个按钮是错误所指的地方。我不知道怎么了。我是编程新手。任何帮助都将不胜感激 AttributeError: App instance has no attribute 'h_one' 我的代码: from Tkinter import * import tkMessageBox class App: def __init__(self, master): frame =
AttributeError: App instance has no attribute 'h_one'
我的代码:
from Tkinter import *
import tkMessageBox
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(
frame, text="QUIT", fg="red", command=frame.quit
)
self.button.pack(side=LEFT,padx=5)
self.hone = Button(frame, text="Happy #1", command=self.h_one)
self.hi_there.pack(side=BOTTOM,pady=5)
self.htwo = Button(frame, text="Happy #2", command=self.h_two)
self.hi_there.pack(side=BOTTOM,pady=5)
self.hthree = Button(frame, text="Happy #3", command=self.h_three)
self.hi_there.pack(side=BOTTOM,pady=5)
def h_one(self):
print "1"
def h_two(self):
print "2"
def h_three(self):
print "3"
frame=Tk()
frame.title("Mad Mike's Happy Tool")
frame.geometry("360x400+200+200")
label0 = StringVar()
label0.set("MMHT")
labelA = Label(frame, textvariable=label0, height = 4)
labelA.pack(side=BOTTOM)
app = App(frame)
frame.mainloop()
frame.destroy()
问题是您试图在类init函数中定义h函数。 请尝试支持def h_3;。。。函数一级缩进,如下所示
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(
frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT,padx=5)
self.hone = Button(frame, text="Happy #1", command=self.h_one)
self.hi_there.pack(side=BOTTOM,pady=5)
self.htwo = Button(frame, text="Happy #2", command=self.h_two)
self.hi_there.pack(side=BOTTOM,pady=5)
self.hthree = Button(frame, text="Happy #3", command=self.h_three)
self.hi_there.pack(side=BOTTOM,pady=5)
def h_one(self):
print "1"
def h_two(self):
print "2"
def h_three(self):
print "3"
看看你的压痕;查看
h\u one
和其他方法如何比\uu init\uuu
方法缩进得更远?试着解决这个问题。是的,就是这样,谢谢你们两位的快速回复。对不起,我问的问题这么简单。我只是觉得它看起来不错。谢谢