确定哪个小部件在 wxpython 中触发了 EVT_MOUSE_ENTER
有没有办法找出哪个小部件触发了 EVT_MOUSE_ENTER 事件或 EVT_MOUSE_LEAVE 事件?我有 42 个小部件排列在 6*7 的 gridsizer 中,我希望它们每个都以相同的方式响应这两个事件。不幸的是,我查看了文档,发现只有按钮单击事件才能使用 event.GetId() 之类的方法追溯到其源。我的说法正确吗?如果有人能证明我错了,这将为我节省大量代码。
谢谢。
Is there any way of finding out which widget triggered an EVT_MOUSE_ENTER event or an EVT_MOUSE_LEAVE event? I've got 42 widgets arranged in a 6*7 gridsizer, and I want them each to respond to these two events in the same way. Unfortunately I've looked in the documents and it appears that only button-click events can be traced back to their source using things like event.GetId(). Am I right about this? It will save me a huge amount of code If someone can show that I'm wrong.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您正在寻找的,但无论如何它在 Windows 上对我有用:
这个想法是将小部件绑定到同一个处理程序,然后使用 GetEventObject() 来确定哪个小部件调用了所述处理程序。然后,您可以使用小部件自身的自省,通过 GetId() 或 GetName() 来确定它是哪一个。有关更多信息,请查看本教程:http://www.blog.pythonlibrary.org/2011/09/20/wxpython-binding-multiple-widgets-to-the-same-handler/
I'm not sure if this is what you're looking for, but it works for me on Windows at any rate:
The idea is to bind the widgets to the same handler, then use GetEventObject() to determine which widget called said handler. Then you can use the widget's own introspection to figure out which one it is via GetId() or GetName(). For more information, check out this tutorial: http://www.blog.pythonlibrary.org/2011/09/20/wxpython-binding-multiple-widgets-to-the-same-handler/