1
我嘗試從python2.7 PyGTK的我的應用程序切換到Python3和pyGObject以及具有附加行我Gtk.ListStore困難時期:/如何將行附加到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')
給我總是錯誤:
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()
這是怎麼回事?如何將新行添加到Gtk.ListStore中?