I’m trying to create a Gtk popup menu on button click using a handler as seen below:
def code_clicked(self,widget,event):
newmenu=Gtk.Menu()
newitem=Gtk.MenuItem('hello')
newmenu.append(newitem)
newitem1=Gtk.MenuItem('goodbye')
newmenu.append(newitem1)
newmenu.show_all()
newmenu.popup(None,None,None,None,event.button,event.time)
return True
The menu never appears. Theoretically, the third argument in popup, func, sets the position to the cursor position if set to Null. I think the problem is there since if I set func to lambda x,y: (event.x,event.y,True), it shows the popup menu some 100 pixels above my cursor.
I’d like to find some way to popup this menu at my cursor. Any help would be appreciated!
You need the root position of the window.
So
should put the popup at correct position. Works here.
As to answer of Jon Black, in GTK3, the question is correct, see http://developer.gnome.org/gtk3/3.4/GtkMenu.html#gtk-menu-popup The deprecate pygtk bindings only work like you describe