在PyGObject中向treeview添加项目

时间:2011-11-09 21:18:52

标签: python gtk glade pygobject gtktreeview

我在Glade中创建了一个GUI,我想填充treeview小部件。这是我的代码的相关部分

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)

然而,当我尝试运行代码时,我收到一个错误,通知我没有定义渲染器。违规行是

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

有人可以指出错误吗?如果它有帮助,这里是追溯

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

谢谢,

v923z

1 个答案:

答案 0 :(得分:1)

你确定你没有这样的拼写错误吗?

>>> something = 1
>>> somthing    # typo, left out 'e'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'somthing' is not defined