[pygtk] comboboxes and images

Greg Bair gregbair at gmail.com
Mon Aug 23 04:09:51 WST 2010


Hey everyone,

When trying to insert an image into a combobox, I couldn't find a good 
way online.  So, I dug around the docs, and came up with this solution.

         self.lst_services = gtk.ListStore(str, gtk.gdk.Pixbuf)

	for service in services :

             imagefile = '../../data/' + service + '.png'

             image = gtk.Image()

             image.set_from_file(imagefile)

             pixbuf = image.get_pixbuf()

             

             self.lst_services.append((service, pixbuf))


         cell = gtk.CellRendererText()

         self.cmb_services.pack_start(cell, True)

         self.cmb_services.add_attribute(cell, 'text', 0)


         imagecell = gtk.CellRendererPixbuf()

         self.cmb_services.pack_start(imagecell, False)

         self.cmb_services.add_attribute(imagecell, 'pixbuf', 1)

Just though I'd throw that out there.  If anyone sees a problem with 
this solution, let me know.

Greg


More information about the pygtk mailing list