在做了几个小时令人沮丧的事情后,我希望事情变得简单(在GTK-2中),在此我提出了我的问题。很抱歉在这个问题中缺少代码或细节,因为我没有任何工作。
我正在编写一个应用程序,该应用程序从数据库中提取一些数据,并将其以表格形式呈现出来。我要说的是标准的东西。我就是想不出怎么做。没有教程(并且那些教程对我来说不起作用,因为我的窗口中不仅仅有一个ListStore )。我在Glade中设计我的UI,它有一个笔记本,里面有一个网格,里面有各种各样的东西,包括列表应该出现的地方。
我尝试添加一个ListStore对象,但根本不能显示它。Python 2.7.6,Glade 3.16.1。
self.liststore = self.builder.get_object('liststore1')
self.liststore.append(['1st column','2nd column'])这本应显示数据,但事实并非如此。我无法让Glade中的ListStore对象显示为预览,只能将其添加为顶层对象,而不能将其添加到预期的位置。
发布于 2014-07-18 01:14:29
这是一个非常基本的示例,它只显示了一列和两个条目。其中一个是在glade文件中创建的,另一个是使用python创建的,因此您可以看到如何修改liststore:
glade文件:
<?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文件:
from gi.repository import Gtk
class Test:
def __init__(self):
builder = Gtk.Builder()
builder.add_from_file('test.glade')
self.liststore = builder.get_object('liststore1')
#append something with python:
self.liststore.append(('stackoverflow',))
window = builder.get_object('window1')
window.connect('delete-event', Gtk.main_quit)
window.show_all()
if __name__ == '__main__':
Test()
Gtk.main()https://stackoverflow.com/questions/24191132
复制相似问题