I needed to tidy and reorganise your code a little, as it was hard to
see what was wrong at first. Couple of issues:

* The TreeViewColumn needed packing into the TreeView
* You had requested two columns of data to be displayed, but only
provided the ListStore with one column worth of data (two columns being
named 'Users' and 'Bammurdo').
* When attaching a TreeViewColumn, there are two things you need; to
issue a packing and to set the attributes. The packing was missing which
would prevent it from displaying the content.

Hopefully, below is what you need.

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()
        * The ListStore had no content
        self.listStore = gtk.ListStore(gobject.TYPE_STRING)
        self.listStore.append(["Text in a TreeView"])
        
        self.treeView = gtk.TreeView()
        self.treeView.set_model(self.listStore)
        self.cellRenderer = gtk.CellRendererText()
        self.treeViewColumn = gtk.TreeViewColumn("Users")
        self.treeViewColumn.pack_start(self.cellRenderer, True)
        self.treeViewColumn.add_attribute(self.cellRenderer, "text", 0)
        self.treeView.append_column(self.treeViewColumn)
        
        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(self.treeView, True, True, 0)
        
        self.window.show_all()

PyGTKApp()
gtk.main()

If you're just starting out with PyGTK, the TreeView is arguably the
hardest widget set you could have started with. It really is very
complex, albeit powerful.

On Mon, 2011-12-12 at 18:39 +0000, [email protected] wrote:
> 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.
> _______________________________________________
> pygtk mailing list   [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/

-- 
Andrew Steele <[email protected]>

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to