简体   繁体   English

是否可以将事件绑定到菜单而不是wxPython中的菜单项?

[英]Is it possible to bind an event against a menu instead of a menu item in wxPython?

没有补充

Do you want an event when your menu is opened? 打开菜单时是否要活动? Use EVT_MENU_OPEN(func) ( wxMenuEvent ). 使用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. 对于另一个事件,您必须关闭它并再次打开另一个菜单。 Ie 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. 可能还有另一种方法可以代替监听此类事件。

If you want an event for all items of a menu, use EVT_MENU_RANGE(id1, id2, func) (it's using wxCommandEvent ). 如果要为菜单的所有项目都需要一个事件,请使用EVT_MENU_RANGE(id1, id2, func) (使用wxCommandEvent )。 All IDs starting from id1 up to and including id2 will be connected to the given event handler. id1到包括id2所有ID都将连接到给定的事件处理程序。 Using a range instead of connecting each item separate will provide for better performance, as there are fewer items in the event-handler list. 使用范围而不是单独连接每个项目将提供更好的性能,因为事件处理程序列表中的项目较少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM