Search code examples
pythoncomboboxgtkappendvbox

Python: gtk.ComboBox append box


Here's the case: I want to append multiple gtk.VBox()'es to a gtk.ComboBox. Haven't found a way to do it yet, but searched quite a while.

Thanks in advance

EDIT: the main thing I want to reach with this is to get an image besides the text inside the ComboBox. Thank you.


Solution

  • You can add a CellRendererPixbuf to the ComboBox like you would in a TreeView:

    model = gtk.ListStore(gtk.gdk.Pixbuf, str)
    model.append([gtk.gdk.pixbuf_new_from_file('image.png'), 'Foo'])
    
    cb = gtk.ComboBox(model)
    
    pb_cell = gtk.CellRendererPixbuf()
    cb.pack_start(pb_cell, False)
    cb.add_attribute(pb_cell, 'pixbuf', 0)
    
    txt_cell = gtk.CellRendererText()
    cb.pack_start(txt_cell, True)
    cb.add_attribute(txt_cell, 'text', 1)