<p>我有一个树视图,在给定的列中有一个cellRenderCombo。我使用以下代码设置列:</p>
<pre><code>crc = gtk.CellRendererCombo()
crc.set_property('model', comboModel)
crc.set_property('text-column', 0)
crc.set_property('editable', True)
crc.set_property('has_entry', False)
cl = gtk.TreeViewColumn(ctitle, crc, text=i)
def changed(cell, path, newiter):
treeViewModel[path][0] = "HAH"
crc.connect("changed", changed)
treeView.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>_column(cl)
</code></pre>
<p><code>treeView</code>是<code>TreeView</code>,<code>treeViewModel</code>是它的模型,<code>comboModel</code>是只包含两个字符串的组合项的模型。在</p>
<p>如果我运行代码,那么组合框将按预期工作,但第一次选择条目时会出现以下错误:</p>
^{pr2}$
<p>第二次我得到:</p>
<pre><code>c:\python25\lib\site-packages\twisted\internet\gtk2reactor.py:255: Warning: inva
lid uninstantiatable type `<invalid>' in cast to `GObject'
gtk.main()
</code></pre>
<p>第三次程序崩溃。如果将连接线更改为:</p>
<pre><code>crc.connect("edited", changed)
</code></pre>
<p>…那么代码就可以正常工作了。但是,该值只在单击组合框后更改,我宁愿每次选择对象时都更改它。我怎样才能做到后者呢?在</p>
<p>编辑:我刚在<a href="http://www.pygtk.org/docs/pygtk/class-gtkcellrenderercombo.html" rel="nofollow noreferrer">API docs for pygtk</a>中注意到了这一点:</p>
<blockquote>
<p>Note that as soon as you change the model displayed in the tree view, the tree view will immediately cease the editing operating. This means that you most probably want to refrain from changing the model until the combo cell renderer emits the edited or editing_canceled signal. </p>
</blockquote>
<p>不过,它没有提到代码会崩溃。在任何情况下,我希望在单击组合框中的条目后,编辑停止,而不必按ENTER键或单击其他位置。我怎么才能做到呢?在</p>