使用Python和GTK3在treeview列中放置文本左侧的图标

时间:2015-04-14 18:52:58

标签: python treeview gtk icons gtk3

我使用此代码将图标添加到TreeView列:

 def build_tree_view(self):
    self.explorer_store = Gtk.TreeStore(Pixbuf, str, str)
    icon = Gtk.IconTheme.get_default().load_icon("folder", 22, 0)
    for connname, conndata in self.config.get('connections', {}).items():
        parent = self.explorer_store.append(None, [icon, connname, self.get_dsn(conndata)])
    self.tree_view = Gtk.TreeView(self.explorer_store)

    renderer_pixbuf = Gtk.CellRendererPixbuf()
    renderer_text = Gtk.CellRendererText()

    column1 = Gtk.TreeViewColumn("Column", renderer_text)

    column1.pack_start(renderer_text, True)
    column1.pack_start(renderer_pixbuf, False)

    column1.add_attribute(renderer_pixbuf, "pixbuf", 0)
    column1.add_attribute(renderer_text, "text", 1)
    self.tree_view.append_column(column1)

我得到了这个结果:

TreeView

如何将图标对齐文本左侧?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!当我创建一个列时,我不需要将渲染器作为第二个参数传递:

column1 = Gtk.TreeViewColumn("Column", renderer_text)

正确的代码是:

column1 = Gtk.TreeViewColumn("Column")