[pygtk] Using TreeView in PyGTK

ben at b3ns.com ben at b3ns.com
Tue Dec 13 02:39:00 WST 2011


Hi,

I am figuring out the basics of PyGTK, and I am trying to get a 
ListView so I can display a list of usernames. I don't think I am doing 
it right and nothing is displayed when executing the PyGTK application. 
The code is below - thanks:

import gtk
import gobject

class PyGTKApp:
         button = gtk.Button("Click Here!")
         hBox = gtk.HBox()
	hBox2 = gtk.HBox()
         vBox = gtk.VBox()
         def __init__(self):
                 self.window = gtk.Window()
		self.treeView = gtk.TreeView()
		self.listStore = gtk.ListStore(gobject.TYPE_STRING)
		self.cellRenderer = gtk.CellRendererText()
		self.treeViewColumn = gtk.TreeViewColumn("Users", self.cellRenderer, 
text=0)
		self.appendC = self.treeViewColumn.add_attribute(self.cellRenderer, 
"Bammurdo", 1)
                 self.window.set_title("PyGTK Application")
                 self.window.connect("destroy", gtk.main_quit)
                 self.window.set_size_request(400,100)
                 self.window.add(self.vBox)
                 self.vBox.pack_start(self.hBox,0)
		self.vBox.pack_start(self.hBox2,0)
                 self.hBox.pack_start(gtk.HBox(),1,0)
                 self.hBox.pack_start(self.button,0,0)
                 self.hBox.pack_start(gtk.HBox(),1,0)
		self.hBox2.pack_start(gtk.HBox(),1,0)
		self.hBox2.pack_start(self.treeView)
		self.hBox2.pack_start(gtk.HBox(),1,0)
                 self.window.show_all()
PyGTKApp()
gtk.main()

Best Regards.


More information about the pygtk mailing list