擅长:python、mysql、java
<p>感谢前面所有的答案,但是我认为最终的解决方案应该包括TreeModel(带TreeStore)可以存储具有多个嵌套级别的项(例如path(2,0,4,2))。“fresh”发布的解决方案对我不起作用,因为我需要一个能够正确遍历所有最后一个子级的函数,直到它真正找到最后一行。以下是我的最终解决方案:</p>
<pre><code>def get_last_iter (self, model):
n = model.iter_n_children (None)
# list empty
if n == 0:
return None
else:
iter = model.iter_nth_child (None, n - 1)
n = model.iter_n_children (iter)
# last top-level item has no children, so select that last item
if n == 0:
return iter
else:
# traverse thru every last child
while 1:
iter = model.iter_nth_child (iter, n - 1)
n = model.iter_n_children (iter)
if n == 0:
return iter
</code></pre>
<p>或者更简短的形式:</p>
^{pr2}$