python tk 的奇怪错误
class Application(tk.Frame):
def __init__(self,master=None):
tk.Frame.__init__(self,master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.end=tk.Button(self,text="end",fg="red",command=self.end)
self.end.pack(side="bottom")
self.start=tk.Button(self)
self.start["text"]="start"
self.start["command"]=self.start
self.start.pack(side="top")
def start(self):
print("start button clicked!")
def end(self):
print("end button clicked!")
root=tk.Tk()
app=Application(master=root)
app.mainloop()
点击start不管用,但是把start改成start1就能用了
本来猜测类本身有start函数 但是自己简单测试发现没有
请大家帮帮忙 python 类 tk
[解决办法]
命名不妥发生覆盖,self.start,self.end不可能同时是按钮控件,又是回调函数,改名字是必须的...