是否可以针对 wxPython 中的菜单而不是菜单项绑定事件? [英] Is it possible to bind an event against a menu instead of a menu item in wxPython?

查看:40
本文介绍了是否可以针对 wxPython 中的菜单而不是菜单项绑定事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没什么可补充的

推荐答案

您想要在菜单打开时发生事件吗?使用 EVT_MENU_OPEN(func) (wxMenuEvent).但它不是特别精确.正如文档所说,如果您打开菜单,它只会发送一次.对于另一个事件,您必须关闭它并再次打开另一个菜单.即在两者之间,您可以打开其他菜单(通过将鼠标悬停在菜单栏中的其他项目),并且不会再次发送该事件.

Do you want an event when your menu is opened? Use EVT_MENU_OPEN(func) (wxMenuEvent). But it's not in particular precise. As the documentation says, it is only sent once if you open a menu. For another event you have to close it and open another menu again. I.e in between, you can open other menus (by hovering other items in the menubar), and the event won't be sent again.

你需要这个做什么?可能还有另一种方法可以做到,而不是侦听此类事件.

What do you need this for? Probably there is another way to do it, instead of listening for this kind of event.

如果你想要一个菜单​​的所有项目的事件,使用 EVT_MENU_RANGE(id1, id2, func)(它使用 wxCommandEvent).从 id1 到并包括 id2 的所有 ID 都将连接到给定的事件处理程序.使用范围而不是单独连接每个项目将提供更好的性能,因为事件处理程序列表中的项目较少.

If you want an event for all items of a menu, use EVT_MENU_RANGE(id1, id2, func) (it's using wxCommandEvent). All IDs starting from id1 up to and including id2 will be connected to the given event handler. Using a range instead of connecting each item separate will provide for better performance, as there are fewer items in the event-handler list.

这篇关于是否可以针对 wxPython 中的菜单而不是菜单项绑定事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆