Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top