Search code examples
pythonuser-interfacepygtk

Why PyGTK ListStore Adds New Record With The Same Values?


I've implement a GUI with PyGTK with below code:

swin = gtk.ScrolledWindow()
swin.set_shadow_type(gtk.SHADOW_ETCHED_IN)
self.lstore = gtk.ListStore(str, str, str, str, str, str)
self.tree = gtk.TreeView(self.lstore)
for i in range(6):
    row = gtk.CellRendererText()
    cell = gtk.TreeViewColumn("Arg %d" % i, row, text=0)
    self.tree.append_column(cell)
swin.add(self.tree)
self.lstore.append(['a', 'b', 'c', 'd', 'e', 'f']) #Add new record.

But it shows a new record with the same values:

enter image description here


Solution

  • The problem is in

    cell = gtk.TreeViewColumn("Arg %d" % i, row, text=0)
    

    That tells all your cells to display the text from column 0. You probably want

    cell = gtk.TreeViewColumn("Arg %d" % i, row, text=i)