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()`
这就是错误:
super(Application, self).__init__(master)
TypeError: super() argument 1 must be type, not classobj
我做错什么了?代码在Python3.XX中运行良好,但在Python2.XX中却没有
TKinter.Frame
是Python 2上的一个旧样式类。像super
这样的功能不能使用它。直接参考Frame.__init__
:Frame
不是新样式的类,但是super
需要新样式的类才能工作。在python-3.x中,一切都是一个新样式的类,super
将正常工作。您需要在Python2中硬编码超类和方法:
就像他们在official documentation里那样。
相关问题 更多 >
编程相关推荐