#!/usr/bin/env python try: import gobject, gtk, pango except: print >> sys.stderr, _("You need to install the python bindings for " \ "gobject, gtk and pango to run this example.") sys.exit(1) DATA = [ {'col1' : 'row 1/col 1', 'col2' : 'row 1/col 2', 'fg': '#000000', 'bg': '#FF00FF', 'paint_2nd_row' : False}, {'col1' : 'row 2/col 1', 'col2' : 'row 2/col 2', 'fg': '#FF0F0F', 'bg': '#C9C9C9', 'paint_2nd_row' : False}, {'col1' : 'row 3/col 1', 'col2' : 'row 3/col 2', 'fg': '#000FFF', 'bg': '#FFF000', 'paint_2nd_row' : True}, ] class Window(gtk.Window): def __init__(self): gtk.Window.__init__(self) self.set_title("ListStore Example") self.connect("destroy", lambda w: gtk.main_quit()) self.connect("delete_event", lambda w, e: gtk.main_quit()) #we create the store and append our elements liststore = gtk.ListStore(str, str, str, str, bool) for i in DATA: liststore.append([i['col1'], i['col2'], i['fg'], i['bg'],i['paint_2nd_row']]) treeview = gtk.TreeView(liststore) #First column's cell cell = gtk.CellRendererText() col = gtk.TreeViewColumn("Column 1") col.pack_start(cell, True) #the first column is always painted cell.set_property('background-set' , True) cell.set_property('foreground-set' , True) col.set_attributes(cell,text=0, foreground=2, background=3) treeview.append_column(col) #Second column's cell cell = gtk.CellRendererText() col = gtk.TreeViewColumn("Column 2", cell, text=1, foreground=2, background=3, foreground_set=4, background_set = 4) treeview.append_column(col) self.add(treeview) self.show_all() if __name__ == "__main__": #window creation win = Window() #enter the main loop gtk.main()