gpt4 book ai didi

python - 如何将行附加到 Gtk.ListStore?

转载 作者:太空宇宙 更新时间:2023-11-04 10:49:23 26 4
gpt4 key购买 nike

我正在尝试将我的应用程序从 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?

最佳答案

只需使用以下命令:

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

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

关于python - 如何将行附加到 Gtk.ListStore?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14922533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com