BPS*_*BPS 2 python pygtk pygobject gtk3
我试图将我的应用程序从 python2.7 pyGTK 切换到 Python3 和 pyGObject,并且很难将行附加到我的 Gtk.ListStore :/
这段代码:
#!/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')
Run Code Online (Sandbox Code Playgroud)
总是给我错误:
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()
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?如何将新行追加到 Gtk.ListStore 中?
只需使用以下命令:
itr = store.append(['Its working', ])
Run Code Online (Sandbox Code Playgroud)
您可以在Python GTK+ 3 教程中找到更多示例。