GTK ComboBox是空的

时间:2017-10-23 05:41:41

标签: gtk pygobject

我有一个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()

1 个答案:

答案 0 :(得分:2)

你的组合框缺少一个渲染器。

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