Fli*_*imm 3 python gtk pygobject
如何创建一个显示条目列表的ComboBox,每个条目包含一些文本和一个图标?
我正在使用Python和GTK3与GObject内省.
这是一个如何做到这一点的例子,受到这个答案的启发.
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()
Run Code Online (Sandbox Code Playgroud)