PyGTK 和树视图
我正在尝试将树视图添加到我的 PyGTK 应用程序中。
这是它在 Glade 中的外观:
还有主窗口代码,我试图在其中添加附加一些数据到我的树视图中:
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])
但是,当我运行应用程序时,我得到的是空的树视图:
当我向树添加行时,也会发生同样的情况从林间空地看去。
我做错了什么?
I'm trying to add Tree View to my PyGTK app.
Here is how it looks in Glade:
And there is the main window code where I'm trying to add append some data to my Tree View:
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])
But empty Tree View is what I get when I run the app:
Same happens when I add rows to Tree View from Glade.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要在
ListStore
下添加一个TreeViewColumn
和一些CellRenderer
来显示模型中已有的列。为此,请选择
TreeView
小部件并单击Edit
按钮。将打开一个对话框(类似于用于编辑菜单的对话框),以便您可以添加列和向列添加渲染器。之后,模型中的任何更改都将显示在树视图中。I think you need to add a
TreeViewColumn
under yourListStore
with someCellRenderer
to display the column you already have in the model.To do that, select the
TreeView
widget and click on theEdit
button. A dialog will be opened (similar to the one used to edit menus) so that you can add columns and renderers to the columns. After that, any changes in the model will be displayed in the treeview.