GTK 组合框为空

GTK ComboBox is empty

我有一个 Gtk.Grid,我想向其中添加一行带有组合框的行,该组合框使用列表进行初始化。但是,我的组合框是空的。谁能看到我在这里遗漏了什么?

我参考了this tutorial

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()

您的组合框缺少渲染器。

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()