Oded Sayar
Oded Sayar

Reputation: 429

GTK ComboBox is empty

I have a Gtk.Grid to which I want to add a row with a combo box, which is initialized with a list. However, my combo box is empty. Can anyone see what I'm missing here?

I used this tutorial as reference

queryTypes = ["Name", "Grade", "Year", "Faculty"]
queryStore = Gtk.ListStore(str)
for qt in queryTypes:
    queryStore.append([qt])

window = builder.get_object("mainWindow")

grid = builder.get_object("queryGrid")
grid.nRows = 1

combox = Gtk.ComboBox.new_with_model(queryStore)
grid.add(combox)

window.show_all()
Gtk.main()

Upvotes: 0

Views: 422

Answers (1)

theGtknerd
theGtknerd

Reputation: 3745

Your combobox is missing a renderer.

queryTypes = ["Name", "Grade", "Year", "Faculty"]
queryStore = Gtk.ListStore(str)
for qt in queryTypes:
    queryStore.append([qt])

window = builder.get_object("mainWindow")

grid = builder.get_object("queryGrid")
grid.nRows = 1

combox = Gtk.ComboBox.new_with_model(queryStore)
renderer_text = Gtk.CellRendererText()
combox.pack_start(renderer_text, True)
combox.add_attribute(renderer_text, "text", 0)
grid.add(combox)

window.show_all()
Gtk.main()

Upvotes: 2

Related Questions