如何在wxPython中获取事件的详细信息

发布于 2024-11-18 01:31:40 字数 398 浏览 3 评论 0原文

我有一段代码返回滑块生成的事件。

我使用 self.Bind(wx.EVT_SCROLL,self.OnSlide) 绑定事件。

处理该事件的代码如下所示:

def OnSlide(self,event):
    widget = event.GetEventObject()

这很好,但每次执行代码时都会抛出错误。它显示:

AttributeError: 'PyEventBinder' object has no attribute 'GetEventObject'

我希望能够查看哪个滑块生成了该事件,但每次我尝试查找时都会出现错误。

如何才能让代码正确执行呢?

非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥有 2024-11-25 01:31:40

要调试类似的内容,请将以下内容作为事件处理程序中的第一个语句:

import pdb; pdb.set_trace()

这将在此时停止程序的执行并为您提供交互式提示。然后,您可以发出以下命令来找出可用的方法:

print dir(event)

当我第一次学习 wxPython 时,我发现这种技术非常宝贵。

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.

那小子欠揍 2024-11-25 01:31:40

以下内容适用于 Windows 7、wxPython 2.8.10.1、Python 2.5

import wx

class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, title="Tutorial")

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        slider = wx.Slider(panel, size=wx.DefaultSize)
        slider.Bind(wx.EVT_SLIDER, self.onSlide)

    #----------------------------------------------------------------------
    def onSlide(self, event):
        """"""
        obj = event.GetEventObject()
        print obj

#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

The following works for me on Windows 7, wxPython 2.8.10.1, Python 2.5

import wx

class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, title="Tutorial")

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        slider = wx.Slider(panel, size=wx.DefaultSize)
        slider.Bind(wx.EVT_SLIDER, self.onSlide)

    #----------------------------------------------------------------------
    def onSlide(self, event):
        """"""
        obj = event.GetEventObject()
        print obj

#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文