英文:
When does wxpython event object get declared within the Bind and event handling logic?
问题
在代码中,"e" 是事件对象的参数,它不需要在函数中显式地声明,而是由事件系统自动传递给事件处理程序。所以,"e" 不需要在函数中像你所期望的那样显式声明,它会在事件触发时自动传递给 "OnSliderScroll" 函数。
英文:
I have working wxpython code, but I don't understand some logic. In the code, a scroll event is assigned to an 'OnSliderScroll' event handler.
sld.Bind(wx.EVT_SCROLL, self.OnSliderScroll)
OnSliderScroll is defined as such:
def OnSliderScroll(self, e):
obj = e.GetEventObject()
...
But "e" isn't declared anywhere (at least it isn't done explicitly). I expected something like
e = ...
Where/when does "e" get declared?
答案1
得分: 1
e
是代表事件本身的对象,并且按照惯例传递给所有事件处理程序。它在 wxPython 中定义,这就是为什么你在自己的代码中看不到它,但它在你的事件处理程序定义中声明为其参数。
英文:
e
is the object representing the event itself and passed, by convention, to all event handlers. It's defined inside wxPython itself, which is why you don't see it in your own code, but it's declared in your event handler definition -- as its parameter.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论