PyGTK和Tree Vi

2024-05-16 14:02:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将树视图添加到我的PyGTK应用程序中。在

下面是它在空地上的样子:

enter image description hereenter image description here

在主窗口代码中,我尝试在树视图中添加附加数据:

import gettext
from gettext import gettext as _
gettext.textdomain('repository-notifier')

import gtk
import logging
logger = logging.getLogger('repository_notifier')

from repository_notifier_lib import Window
from repository_notifier.AboutRepositoryNotifierDialog import AboutRepositoryNotifierDialog
from repository_notifier.PreferencesRepositoryNotifierDialog import PreferencesRepositoryNotifierDialog

# See repository_notifier_lib.Window.py for more details about how this class works
class RepositoryNotifierWindow(Window):
    __gtype_name__ = "RepositoryNotifierWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(RepositoryNotifierWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutRepositoryNotifierDialog
        self.PreferencesDialog = PreferencesRepositoryNotifierDialog

        # Code for other initialization actions should be added here.
        self.builder.get_object('listLogModel').append([5])
        self.builder.get_object('listLogModel').append([6])
        self.builder.get_object('listLogModel').append([7])

但是当我运行应用程序时,我得到的是空的树视图:

enter image description here

当我从Glade向树视图添加行时,也会发生同样的情况。在

我做错什么了?在


Tags: fromimportself视图getobjectrepositorybuilder
1条回答
网友
1楼 · 发布于 2024-05-16 14:02:42

我认为您需要在您的ListStore下添加一个TreeViewColumn和一些{}来显示模型中已有的列。在

为此,选择TreeView小部件并单击Edit按钮。将打开一个对话框(类似于用于编辑菜单的对话框),以便您可以向列添加列和渲染器。之后,模型中的任何更改都将显示在树视图中。在

相关问题 更多 >