Search code examples
gtk3pygobject

GtkToolbar: How to add Toolitem to toolbar using PyGObject


How can I add icons to a GtkToolbar using PyGObject?

I can create the toolbar and an icon without any problems:

    self.toolbar = Gtk.Toolbar()
    self.item = Gtk.ToolItem()

But adding the item to the toolbar doesn't seem to work like this (Found this in the PyGTK documentation):

    self.toolbar.Container.add(self.item)

Solution

  • The solution is actually pretty simple:

        self.button = Gtk.ToolButton(Gtk.STOCK_ABOUT)
        self.toolbar.insert(self.button, 0)
    

    User button instead of item and then choose an icon from this list: http://python-gtk-3-tutorial.readthedocs.org/en/latest/stock.html

    Then use .inset with the object and the position (in this case 0, meaning the first item in the toolbar).