python unbound method必须用<MyFrame>实例作为第一个参数调用<myMethod>(没有得到任何结果)

2024-10-02 02:42:59 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图编译时,我得到了错误

C:\Temp\pythonWork\superGui>superGui.py
  Traceback (most recent call last):
  File "C:\Temp\pythonWork\superGui\superGui.py", line 747, in <module>
  MyFrame.disableAll()
  TypeError: unbound method disableAll() must be called with MyFrame instance as first argument (got nothing instead)

代码snipet

class MyFrame(wx.Frame):
    ---- CODE SNIP ----
    def disableAll(self):
        self.btnBeginInstall.Disable()
        self.btnBeginInstall.Disable()
        self.btnInfraSystem.Disable()
        self.btnIwpcSystem.Disable()
        self.btnIwpcSystem.Disable()
        self.btnIwpcIwpcdba.Disable()
        self.btnLdapOc4jadmin.Disable()
        self.btnLdapOrcladmin.Disable()
        self.btnIas_admin.Disable()
        self.btniwpcadmin.Disable()
        self.btnAll.Disable()

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    mainFrame = MyFrame(None, -1, "")
    app.SetTopWindow(mainFrame)
    mainFrame.Show()

    #disable the buttons
    success = MyFrame.disableAll()
    app.MainLoop()

我看了其他几个类似的问题,但答案并没有跳出我,或者更可能是我只是不明白。


Tags: pyselfapp错误tempdisablewxtraceback
3条回答

你把它当作一个类或静态方法来调用。self应该来自哪里?您必须对应该执行某些操作的对象调用方法,即mainFrame.disableAll()

另外,success将是None,因为disableAll不返回任何内容。你想干什么?

mainFrame.disableAll()

而不是

MyFrame.disableAll()

这样就可以了。

您可能需要使用该类的实例。

mainFrame.disableAll()

如其他答案所示,应该做到这一点。

相关问题 更多 >

    热门问题