2013-04-04 51 views

回答

5

下面是如何做到這一點,通過this answer for C啓發的例子。

from gi.repository import Gtk 
from gi.repository import GdkPixbuf 

store = Gtk.ListStore(str, GdkPixbuf.Pixbuf) 

pb = GdkPixbuf.Pixbuf.new_from_file_at_size("picture.png", 32, 32) 
store.append(["Test", pb]) 

combo = Gtk.ComboBox.new_with_model(store) 

renderer = Gtk.CellRendererText() 
combo.pack_start(renderer, True) 
combo.add_attribute(renderer, "text", 0) 

renderer = Gtk.CellRendererPixbuf() 
combo.pack_start(renderer, False) 
combo.add_attribute(renderer, "pixbuf", 1) 

window = Gtk.Window() 
window.add(combo) 
window.show_all() 

window.connect('delete-event', lambda w, e: Gtk.main_quit()) 

Gtk.main() 
2

在GTK2同樣的例子,您的代碼啓發:

import pygtk 
pygtk.require('2.0') 
import gtk 
import gtk.gdk 
import gobject 
import gc 

store = gtk.ListStore(str, gtk.gdk.Pixbuf) 

pb = gtk.gdk.pixbuf_new_from_file("picture.png") 
store.append(["Test", pb]) 

combo = gtk.ComboBox(store) 

renderer = gtk.CellRendererText() 
combo.pack_start(renderer, True) 
combo.add_attribute(renderer, "text", 0) 

renderer = gtk.CellRendererPixbuf() 
combo.pack_start(renderer, False) 
combo.add_attribute(renderer, "pixbuf", 1) 

window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
window.add(combo) 
window.show_all() 

window.connect('delete-event', lambda w, e: gtk.main_quit()) 

gtk.main()