我有一個名爲WxFrame的類,它創建了一個wxPython框架。我添加了一個稱爲createRunButton方法,其接收自和pydepp,這是一個PyDEPP類的對象使用綁定爲wx.Button時的Python TypeError
import wx
class WxFrame(wx.Frame):
def __init__(self, parent, title):
super(WxFrame, self).__init__(parent, title=title)
self.Maximize()
self.Show()
def createRunButton(self,pydepp):
#pydepp.run()
self.runButton = wx.Button(self, label="Run")
self.Bind(wx.EVT_BUTTON, pydepp.run, self.runButton
這是PyDEPP類:
class PyDEPP:
def run(self):
print "running"
我實例,並與運行:
import wx
from gui.gui import WxFrame
from Depp.Depp import PyDEPP
class PyDEPPgui():
"""PyDEPPgui create doc string here ...."""
def __init__(self,pydepp):
self.app = wx.App(False)
##Create a wxframe and show it
self.frame = WxFrame(None, "Cyclic Depp Data Collector - Ver. 0.1")
self.frame.createRunButton(pydepp)
self.frame.SetStatusText('wxPython GUI successfully initialised')
if __name__=='__main__':
#Launch the program by calling the PyDEPPgui __init__ constructor
pydepp = PyDEPP()
pydeppgui = PyDEPPgui(pydepp)
pydeppgui.app.MainLoop()
運行上述代碼時出現的錯誤是: TypeError:run()需要剛好1個參數(給出2)
但是,如果我註釋掉綁定並取消註釋行pydepp.run(),那麼它工作正常。
答案很明顯,我確定,但我從未學過CompSci或OO編碼。