我在 Glade 中创建了一个 GUI,我想填充树视图小部件。这是我的代码的相关部分
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