On 12/10/2011 13:21, Olaf Devik wrote:
> Thanks to both replies. Info from Dieter did the trick, the critical
> line was intcolumn.add_attribute(cell,'text',1).
>
> I tried to set same trough use of
> gtk.TreeView.insert_column_with_attributes, which was ok for the columns
> with string, but failed when an integer was required. When that failed,
> my confusion went to a high level.
Ah yes, insert_column_with_attributes also works (and even
saves a bit of typing). See attachment :)
mvg,
Dieter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygtk
pygtk.require('2.0')
import gtk
class BasicTreeViewExampleWindow(gtk.Window):
__gtype_name__ = 'MyBasictreeViewExampleWindow'
def __init__(self):
gtk.Window.__init__(self)
self.set_title('Treeview example')
self.set_size_request(500, 200)
vbox = gtk.VBox()
self.add(vbox)
self.liststore = gtk.ListStore(str, int)
self.liststore.append(['abcdef', 0])
self.liststore.append(['ghijkl', 1])
self.liststore.append(['mnopqr', 158])
self.liststore.append(['stuvwx', -70])
self.treeview = gtk.TreeView(self.liststore)
self.treeview.set_headers_visible(True)
vbox.pack_start(self.treeview, expand=True, fill=True)
cell = gtk.CellRendererText()
self.treeview.insert_column_with_attributes(-1, 'Description', cell,
text=0)
self.treeview.insert_column_with_attributes(-1, 'Amount', cell, text=1)
def quit(widget, event):
gtk.main_quit()
def main():
examplewindow = BasicTreeViewExampleWindow()
examplewindow.connect('delete_event', quit)
examplewindow.show_all()
gtk.main()
if __name__ == '__main__':
main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/