【发布时间】:2011-12-05 10:21:41
【问题描述】:
我有一个名为 WxFrame 的类,它创建一个 wxPython 框架。我添加了一个名为 createRunButton 的方法,它接收 self 和 pydepp,它是 PyDEPP 类的对象
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 编码。
【问题讨论】:
标签: python wxpython bind argument-passing typeerror