wxPython事件对象在绑定和事件处理逻辑中何时声明?

huangapple go评论62阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月9日 03:12:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定