在遵循官方教程后:tutorial
我仍然在添加行/创建TreeIter对象时遇到问题。这是我的代码的样子:
builder = gtk.Builder()
self.treeview = builder.get_object("treeview")
self.treestore = gtk.TreeStore(str)
self.treeview.set_model(self.treestore)
self.id = gtk.TreeViewColumn('ID')
self.type = gtk.TreeViewColumn("Type")
self.readName = gtk.TreeViewColumn("Filename")
self.set = gtk.TreeViewColumn("Set")
self.treeview.append_column(self.id)
self.treeview.append_column(self.readName)
self.treeview.append_column(self.type)
self.treeview.append_column(self.set)
self.cell = gtk.CellRendererText()
self.cell1 = gtk.CellRendererText()
self.cell2 = gtk.CellRendererText()
self.cell3 = gtk.CellRendererText()
self.id.pack_start(self.cell, True)
self.readName.pack_start(self.cell1, True)
self.type.pack_start(self.cell2, True)
self.set.pack_start(self.cell3, True)
self.id.add_attribute(self.cell, 'text', 0)
self.readName.add_attribute(self.cell1, 'text', 1)
self.type.add_attribute(self.cell2, 'text', 2)
self.set.add_attribute(self.cell3, 'text', 3)
self.treeview.set_reorderable(True)
self.readListVP.add(self.treeview)
iter = self.treestore.get_iter(self.treestore.get_path(iter)) #here's where my problem lies
self.treestore.set_value(None, 0, self.fileCountStr)
self.treestore.set_value(None, 1, "paired-end")
self.treestore.set_value(None, 2, self.file)
self.treestore.set_value(None, 3, self.readSetStr)
答案 0 :(得分:1)
我也发现了代码的一些常见问题:
CellRenderer
太多了!整张桌子只使用一个。Builder()
!这只是愚蠢地使事情过于复杂。