Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding items to treeview in PyGObject

I have a GUI created in Glade, and I would like to populate the treeview widget. Here is the relevant part of my code

def __init__(self):
            .....
    self.fill_store()
    self.add_column(self.widget('treeview_preview'))
    self.widget('treeview_preview').set_pixbuf_column(0)

def fill_store(self):
    self.widget('liststore_preview').clear()
    foo = GdkPixbuf.Pixbuf.new_from_file('9.png')
    da = Gtk.Image.new_from_pixbuf(foo)
    self.widget('liststore_preview').append([da])

def add_column(self, treeview):
    renderer = Gtk.CellRendererPixbuf()
    column = Gtk.TreeViewColumn("Preview", renderer, pixbuf = 0)
    column.set_sort_column_id(0)    
    treeview.append_column(column)

Yet, when I try to run the code, I get an error, which informs me that renderer is not defined. The offending line is

column = Gtk.TreeViewColumn("Preview", renderer, pixbuf = 0)

Can someone point out the error? In case it helps, here is the traceback

Traceback (most recent call last):
File "test.py", line 10, in <module>
class test:
File "test.py", line 48, in test
column = Gtk.TreeViewColumn("Preview", r, pixbuf = 0)
NameError: name 'r' is not defined

Thanks,

v923z

like image 903
v923z Avatar asked Jun 29 '26 06:06

v923z


1 Answers

Are you sure you don't have an typo like this?

>>> something = 1
>>> somthing    # typo, left out 'e'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'somthing' is not defined
like image 141
Steven Rumbalski Avatar answered Jul 01 '26 19:07

Steven Rumbalski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!