Search code examples
pythongtkfocuspopupmenu

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. 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. 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.


Solution

  • 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:

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