PyGobject에서 나는이 해결책을 생각해 냈습니다. 이 예제는 완전히 작동하지만 동일한 디렉토리에 2 개의 png 파일이 필요합니다. 100 x 20 픽셀 형식의 두 PNG를 사용했습니다.
이전 예제에서는 Gtk.ComboBox.new_with_model_and_entry()를 사용했으며 그런 종류의 콤보 박스와 함께 사용해야하는 set_entry_text_colum() 함수가 누락되었습니다.
#!/usr/bin/python3
from gi.repository import Gtk, Gdk, GdkPixbuf
class ComboBoxWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ComboBox Pixbuf Example")
self.set_border_width(10)
store = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
solid_line = GdkPixbuf.Pixbuf.new_from_file("solid_line.png")
store.append(["1", solid_line])
dashed_line = GdkPixbuf.Pixbuf.new_from_file("dashed_line.png")
store.append(["2", dashed_line])
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
combo = Gtk.ComboBox.new_with_model(store)
rend_int = Gtk.CellRendererText()
rend_pixbuf = Gtk.CellRendererPixbuf()
combo.pack_start(rend_int, False)
combo.add_attribute(rend_int, "text", 0)
combo.pack_start(rend_pixbuf, True)
combo.add_attribute(rend_pixbuf, "pixbuf", 1)
combo.connect("changed", self.on_combo_changed)
vbox.pack_start(combo, False, False, 0)
self.add(vbox)
def on_combo_changed(self, combo):
tree_iter = combo.get_active_iter()
if tree_iter != None:
model = combo.get_model()
row = model[tree_iter][0]
print("Selected row {0}".format(row))
win = ComboBoxWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
비슷한 질문 :
출처 :
** 개별 ComboBox **에서는 잘 작동하지만 ** treeview에서는 ** 콤보 박스가 아닙니다 **. 개별 combobox에 대한 하스켈 코드는이 게시물에있다. [http://stackoverflow.com/q/28258030/3595992]. – JeanJouX