Glade,python,GTK3:d的列表视图

2024-09-28 17:23:41 发布

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

在经历了几个令人沮丧的小时后,我想做一件简单的事情(在GTK-2中就是这样),我提出了这个问题。很抱歉在这个问题上缺少代码或细节,因为我根本没有工作。在

我正在编写一个应用程序,它从数据库中提取一些数据,并且必须以表的形式显示这些数据。我想是标准的东西。我就是不知道怎么做。没有教程(还有那些教程,对我不管用,因为我的窗口不仅仅是一个列表库)。我在Glade设计我的用户界面,它有一个笔记本,里面有一个网格,里面有各种各样的东西,包括一个列表应该出现的地方。在

我尝试添加一个ListStore对象,但是根本无法显示它。Python2.7.6,Glade 3.16.1。在

    self.liststore = self.builder.get_object('liststore1')
    self.liststore.append(['1st column','2nd column'])

我不能让Glade中的ListStore作为预览显示,只能将它添加为顶层对象,而不能将其添加到目标位置。在


Tags: 数据对象代码selfgtk列表column教程
1条回答
网友
1楼 · 发布于 2024-09-28 17:23:41

一个非常基本的列只显示了两个条目。其中一个是在glade文件中创建的,另一个是用python创建的,这样您可以看到如何修改liststore:

空地档案:

<?xml version="1.0" encoding="UTF-8"?>
<!  Generated with glade 3.16.1  >
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!  column-name test  >
      <column type="gchararray"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">entry</col>
      </row>
    </data>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <property name="default_width">247</property>
    <property name="default_height">188</property>
    <child>
      <object class="GtkTreeView" id="treeview1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="model">liststore1</property>
        <child internal-child="selection">
          <object class="GtkTreeSelection" id="treeview-selection1"/>
        </child>
        <child>
          <object class="GtkTreeViewColumn" id="treeviewcolumn1">
            <property name="title" translatable="yes">test-column</property>
            <child>
              <object class="GtkCellRendererText" id="cellrenderertext1"/>
              <attributes>
                <attribute name="text">0</attribute>
              </attributes>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

这是python文件:

^{pr2}$

相关问题 更多 >