如何获取wxPython中的事件的详细信息 [英] How to get the details of an event in wxPython
问题描述
我将事件绑定到 self.Bind(wx.EVT_SCROLL ,self.OnSlide)
。
处理事件的代码如下所示:
def OnSlide(self,event):
widget = event.GetEventObject()
这是非常好的,但每次执行代码时都会抛出一个错误。它显示为:
AttributeError:'PyEventBinder'对象没有属性'GetEventObject'
我想要看到哪个滑块生成了事件,但每次尝试找出错误时都会出现错误。
如何让代码正确执行?
非常感谢提前。
要调试这样的东西,请将以下内容作为事件处理程序中的第一个语句:
import pdb; pdb.set_trace()
此时将停止程序的执行,并为您提供交互式提示。然后,您可以发出以下命令,找出可用的方法:
print dir(event)
当我第一次学习wxPython时,我发现这种技术是无价的。
I have a section of code which returns events generated by a slider.
I bind the event with self.Bind(wx.EVT_SCROLL,self.OnSlide)
.
The code which handles the event reads something like:
def OnSlide(self,event):
widget = event.GetEventObject()
This is great but an error gets thrown every time the code is executed. It reads:
AttributeError: 'PyEventBinder' object has no attribute 'GetEventObject'
I want to be able to see which of the sliders generated the event but the error appears every time I attempt to find out.
How can I get the code to execute correctly?
Many thanks in advance.
To debug something like this, put the following as the first statement in your event handler:
import pdb; pdb.set_trace()
This will stop the execution of the program at this point and give you an interactive prompt. You can then issue the following command to find out what methods are available:
print dir(event)
When I was first learning wxPython I found this technique invaluable.
这篇关于如何获取wxPython中的事件的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!