在pygtk glade3中选择combobox中的项
我在使用pygtk 2.24和glade 3的时候,遇到了一个关于下拉框(combobox)的问题。当我点击下拉框里的某个选项时,出现了以下错误信息:
interface.py:94: Warning: unable to set property `text' of type `gchararray' from
value of type `glong'
gtk.main()
这是我写的下拉框的代码:
#get the combo box out of the builder and add items to it
self.cbmoRepresentation = builder.get_object("cmbo_representation")
self.iface_list_store = gtk.ListStore(gobject.TYPE_STRING)
self.iface_list_store.append(["Row-Column"])
self.iface_list_store.append(["Row-Number"])
self.iface_list_store.append(["Number-Column"])
self.cbmoRepresentation.set_model(self.iface_list_store)
cell = gtk.CellRendererText()
self.cbmoRepresentation.pack_start(cell, True)
self.cbmoRepresentation.add_attribute(cell, "text", 0)
self.cbmoRepresentation.set_active(-1)
如果能得到一些帮助,我会非常感激 :).
1 个回答
0
我有一个可以用的代码(不过我不使用glade):
liststore = gtk.ListStore(gobject.TYPE_STRING)
combobox = gtk.ComboBox(liststore)
cell = gtk.CellRendererText()
combobox.pack_start(cell, True)
combobox.add_attribute(cell, 'text', 0)
所以我怀疑你的 self.cbmoRepresentation 可能类型不对。 请尝试:
self.cbmoRepresentation = builder.get_object("cmbo_representation")
print type(self.cbmoRepresentation)
检查一下cbmoRepresentation的类型。