我在使用WinForms的IronPython脚本调用OnLoad事件时遇到问题,我已将问题减少到尽可能小的复制情况:
from clr import AddReference, accepts, returns, Self
AddReference("System.Windows.Forms")
AddReference("System.Drawing")
import System
from System.Windows.Forms import *
from System.ComponentModel import *
from System.Drawing import *
class DCCForms: # namespace
class Form1(System.Windows.Forms.Form):
def __init__(self):
self.InitializeComponent()
@returns(None)
def InitializeComponent(self):
self.Name = 'Form1'
self.Text = 'DCC'
self.Load += self._Form1_Load
self.ResumeLayout(False)
self.PerformLayout()
@accepts(Self(), System.Object, System.EventArgs)
@returns(None)
def _Form1_Load(self, sender, e):
pass
class WindowsApplication10: # namespace
@staticmethod
def RealEntryPoint():
Application.EnableVisualStyles()
Application.Run(DCCForms.Form1())
WindowsApplication10.RealEntryPoint();
运行时,我收到错误'TypeError:Object is not callable'。对于行self.Load + = self._Form1_Load。我在尝试设置textboxchanged时也遇到了同样的错误,但是为按钮添加了一个OnClick处理程序。上面编写的代码是从IronPython 1.1.2脚本中修改的,该脚本是从Visual Studio 2008 SDK中的IronPython工作室示例生成的。但是,我在PyDev实例中运行Iron Python 2.6.1。
如果我删除了Load语句,则生成表单并响应OnClick事件(如果已指定)。