简体   繁体   English

从GTK弹出菜单中获取焦点

[英]Grab the focus from GTK popup menu

In my python GTK project, I have a popup menu which pop-ups while typing in a particular text area. 在我的Python GTK项目中,我有一个弹出菜单,在输入特定文本区域时会弹出。 But, when type a letter popup menu get the focus and I can't type anymore in the text area until I click on the text area and grab the focus manually. 但是,当键入字母弹出菜单时,获得焦点,在单击文本区域并手动抓住焦点之前,我无法在文本区域中键入任何内容。 I want to keep the focus to the text area as I type regularly while popup menu comes. 在弹出菜单出现时,我要定期输入文字,因此希望将焦点保持在文本区域。 Can anyone give tell me a way to do this. 谁能告诉我这样做的方法。 I tried widget.grab_focus() method. 我尝试了widget.grab_focus()方法。 But it didn't solve my problem. 但这并不能解决我的问题。

Also I want to know how to set the position of the popup menu. 我也想知道如何设置弹出菜单的位置。 It always appears near by mouse pointer. 它始终显示在鼠标指针附近。 I want it to appear near by my application. 我希望它在我的应用程序附近显示。

Thanks all. 谢谢大家

I ran into the same problem using the C API, the solution was to invoke the following functions, I presume they're approximately similar to the python equivalents: 我使用C API遇到了同样的问题 ,解决方案是调用以下函数,我想它们与python等效项大致相似:

gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(menu);

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

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