How to add a right click menu to Gtk.ListBox?

Title says it all: How to add a right click menu to Gtk.ListBox?
I tried searching for it but couldn’t find anything. I’m probably using the wrong keywords.


Just add a gesture to it: corebird/TweetListBox.vala at cb-1.7 · baedert/corebird · GitHub

Thanks for the tip, unfortunately I’m still unable to make it work. This code adds GestureMultiPress to a ListBox. It should print “pressed” when I click somewhere inside the list.
Do you have any idea of what I’m doing wrong?

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

class ListBoxRowWithData(Gtk.ListBoxRow):
    def __init__(self, data):
        super(Gtk.ListBoxRow, self).__init__() = data

class ListBoxWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="ListBox Demo")

        box_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)

        listbox = Gtk.ListBox()
        items = "This is a sorted ListBox Fail".split()

        for item in items:

        box_outer.pack_start(listbox, True, True, 0)

        gesture =
        # I've also tried CAPTURE
        gesture.connect("pressed", lambda g, n, x, y: print("pressed"))


win = ListBoxWindow()
win.connect("destroy", Gtk.main_quit)


That’s a python issue; you need to keep gesture around after your __init__. Otherwise the gesture will be destroyed at the end of __init__ and removed from the widget.

I feel so dumb right now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.