将项目添加到 PyGObject 中的树视图
我在 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定你没有这样的错别字吗?
Are you sure you don't have an typo like this?