如何将行追加到Gtk.ListStore?

时间:2013-02-17 15:14:05

标签: python pygtk gtk3 pygobject

我试图将我的应用程序从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')

总是给我错误:

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?

1 个答案:

答案 0 :(得分:4)

只需使用以下命令:

itr = store.append(['Its working', ])

您可以在The Python GTK+ 3 Tutorial中找到更多示例。