GUI中缺少文本(PyGObject)

2024-05-15 03:52:16 发布

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

我已经用一个xml描述文件用pyGObject创建了一个GUI,并尝试用GtkTreeView创建一个侧边栏。GtkTreeView在我的GUI中没有在标题和子级中显示任何文本,即使我添加了一些。为什么?我怎样才能修好它?在

侧边栏应显示以下内容:

Parent 1
    Child 1
    Child 2
    Child 3

等等

下面显示了我的代码的简短版本。在

应用程序副本

^{pr2}$

应用程序.xml:UI说明

<?xml version="1.0" encoding="UTF-8"?>
<interface>
    <object class="GtkTreeStore" id="sidebar-store">
        <columns>
            <column type="gchararray"/>
        </columns>
    </object>
    <object class="GtkWindow" id="main-window">
        <property name="title"></property>
        <signal name="delete-event" handler="onDeleteWindow"/>
        <child>
            <object class="GtkBox" id="container">
                <property name="orientation">horizontal</property>
                <child>
                    <object class="GtkTreeView" id="sidebar">
                        <property name="model">sidebar-store</property>
                        <property name="headers-visible">false</property>
                        <child>
                            <object class="GtkTreeViewColumn" id="test-column">
                                <child>
                                    <object class="GtkCellRendererText" id="test-renderer"/>
                                </child>
                            </object>
                        </child>
                    </object>
                </child>
                <child>
                    <object class="GtkBox" id="right-container">
                        <property name="orientation">vertical</property>
                        <child>
                            <object class="GtkButtonBox" id="top-buttonbox">
                                <child>
                                    <object class="GtkButton" id="add-button">
                                        <property name="label">Add</property>
                                    </object>
                                </child>
                                <child>
                                    <object class="GtkButton" id="delete-button">
                                        <property name="label">Delete</property>
                                    </object>
                                </child>
                            </object>
                        </child>
                    </object>
                </child>
            </object>
        </child>
    </object>
</interface>

Tags: columnsstorenameidchild应用程序objectgui
1条回答
网友
1楼 · 发布于 2024-05-15 03:52:16

很简单,您没有将任何列映射到文本呈现器。在

顺便说一句,你用什么编辑器来创建用户界面?你是手写的吗?用空地,那样生活就容易多了。在

在“Glade”中,右键单击树视图->编辑->层次结构->选择单元渲染器->映射到模型中列的文本。在

以下是通过Glade编辑的XML的正确版本。最相关的部分是:

<attributes>
    <attribute name="text">0</attribute>
</attributes>

定义文本单元格呈现器时。在

^{pr2}$

相关问题 更多 >

    热门问题