将项目添加到 PyGObject 中的树视图

发布于 2024-12-14 08:13:21 字数 1087 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生殊途 2024-12-21 08:13:21

你确定你没有这样的错别字吗?

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文