PyGTK - 将行添加到 gtk.TreeStore
按照此处的官方教程进行操作后: 教程
我在添加行/时仍然遇到问题创建一个 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)
After following the official tutorial here: tutorial
I'm still having issues adding rows/creating a TreeIter object. Here's what my code looks like:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还发现了代码中的一些常见问题:
CellRenderer
!整个表只使用一个。Builder()
!这只是愚蠢地让事情变得过于复杂。调查一下我已经问过的问题。
I spot a number of general problems with the code as well:
CellRenderer
's! Use just one for the whole table.Builder()
! It's just stupidly overcomplicating things.Look into the question I've already asked.