[英]How to append rows to Gtk.ListStore?
im trying to switch my application from python2.7 pyGTK to Python3 and pyGObject and having hard time with appending rows to my Gtk.ListStore :/ 我试图将我的应用程序从python2.7 pyGTK切换到Python3和pyGObject,并且很难将行附加到我的Gtk.ListStore:/
This code: 这段代码:
#!/usr/bin/env python3
from gi.repository import Gtk
listStore = Gtk.ListStore(str)
itr = Gtk.TreeIter()
listStore.append(itr)
listStore.set_value(itr, 0, 'Its working')
gives me always error: 给我总是错误:
Traceback (most recent call last):
File "./test.py", line 7, in <module>
listStore.append(itr)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 1017, in append
return self._do_insert(-1, row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 1008, in _do_insert
row, columns = self._convert_row(row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 850, in _convert_row
if len(row) != n_columns:
TypeError: object of type 'TreeIter' has no len()
what is going on? 到底是怎么回事? How can I append new row into Gtk.ListStore? 如何将新行追加到Gtk.ListStore?
Simply use the following command: 只需使用以下命令:
itr = store.append(['Its working', ])
You can find more example in The Python GTK+ 3 Tutorial . 您可以在The Python GTK + 3 Tutorial中找到更多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.