TypeError: super() argument 1 must be type, not classobj
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from Tkinter import * class Application(Frame): def __init__(self, master): super(Application, self).__init__(master) self.grid() self.bttnClicks = 0 self.createWidgets() def createWidgets(self): self.bttn = Button(self) self.bttn["text"] ="number of clicks" self.bttn["command"] = self.upadteClicks self.bttn.grid() def upadteClicks(self): self.bttnClicks += 1 self.bttn["text"] ="number of clicks" + str(self.bttnClicks) root = Tk() root.title("button that do something") root.geometry("400x200") app = Application(root) root.mainloop()` |
这就是错误:
1 2 | super(Application, self).__init__(master) TypeError: super() argument 1 must be type, not classobj |
我做错什么了?代码在python 3.xx中工作得很好,但在python 2.xx中却没有。
您需要在python 2中硬编码超类和方法:
1 | Frame.__init__(self, master) |
就像在官方文件中一样。
1 | Frame.__init__(self, master) |