【问题标题】:Python: Unbound MethodsPython:未绑定的方法
【发布时间】:2014-06-30 02:39:43
【问题描述】:

这里是我收到的错误的序言:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "TestR.py", line 13, in __init__ wx.Frame.__init__(self, parent = None, title = "Input Data", size = (1250, 750)) TypeError: unbound method __init__() must be called with Frame instance as first argument (got nothing instead)

当我输入这个时:

j = Test(None, "hello")

使用此代码:

  import wx


class Test(wx.Frame):

def __init__(self, parent, title):
    wx.Frame.__init__(self, parent = None, title = "Input Data", size = (1250, 750))

【问题讨论】:

  • 这不是你使用super的方式。第一个参数是您正在编写的类的名称,而不是超类。此外,如果您的基类未设计为在多重继承中协同工作,则不能将__super__ 用于__init__ 调用。 (如果它们被设计为这样一起工作,您只需拨打一个__super__ 电话。)
  • 已编辑 - 仍然是个问题。
  • 你能显示完整的回溯吗?
  • 你为什么要继承 DataFrame 类呢?您可以在这里使用“适配器模式”或“依赖注入”
  • 就是整个回溯

标签: python python-2.7 wxpython


【解决方案1】:

添加这些行。

import wx

app = wx.App(False)
Test(None, "hello")
app.MainLoop()

【讨论】:

    猜你喜欢
    • 2010-11-04
    • 2011-04-03
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2016-05-19
    • 1970-01-01
    相关资源
    最近更新 更多