- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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
我做错了什么?该代码在 python 3.XX 中运行良好,但在 python 2.XX 中则不然。
最佳答案
Frame
不是新式类,但 super
需要新式类才能工作。在 python-3.x 中,一切都是新式类,super
将正常工作。
您需要在 python 2 中硬编码父类(super class)和方法:
Frame.__init__(self, master)
就像他们在 official documentation 中所做的那样.
关于python - 类型错误 : super() argument 1 must be type, 不是 classobj,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43767988/
我有这段代码,但我无法运行它,因为我得到了这个错误:“TypeError:'classobj' 对象不可订阅”这是我的代码: import cgi import customerlib form=cg
从另一个类方法内部使用 self.methodname() 调用类方法时出现以下错误。 TypeError: 'classobj' object is not subscriptable 可能是什么问
根据 here : The __mro__ attribute of the type lists the method resolution search order used by both ge
我在 saucelabs example.py 文件中使用 import new 模块找到了以下代码片段。 import new # .. snip .. def on_platforms(platf
作为一名 Python 新手,我构建了一个庞大且庞大的项目,虽然相当丑陋,但却满足了我的要求。但我刚刚打破了它。 我试图调用单独文件夹中保存的各种脚本,例如 execfile("folder1/scr
super() 的以下使用引发了 TypeError:为什么? >>> from HTMLParser import HTMLParser >>> class TextParser(HTMLPars
我真的希望我能在这里更具体一些,但我已经通读了相关问题,但似乎没有一个与我在这里遇到的问题有关,而且我也不了解我遇到的问题。这是一个家庭作业,所以我犹豫要不要把我所有的程序代码都贴出来,这是一个精简版
例如; 我想转变 {Aug 07, 2020: [Instance of 'ActivityLog', Instance of 'ActivityLog'], Aug 04, 2020: [Insta
这个问题已经有答案了: How to use super() when subclassing Tkinter widgets? [duplicate] (2 个回答) super() fails w
我有一个类 - A - 没有方法,只有主要方法。 在其他类(class) - B - 我需要调用那个 main.做什么最好?从使用的资源、时间和功耗以及效率来看? 从类 A 创建一个“a”对象并执行
在 Python 中,我试图在类中运行一个方法,但出现错误: Traceback (most recent call last): File "C:\Users\domenico\Desktop\
我遇到了一些我无法弄清楚的错误。任何线索我的示例代码有什么问题? class B: def meth(self, arg): print arg class C(B):
当我运行下面提供的代码时,出现以下错误: 类型错误:必须使用 Page 实例作为第一个参数调用未绑定(bind)方法 setSize()(改为使用 int 实例) In my main, I call
我是一名优秀的程序员,十分优秀!