gtk ComboBoxEntry.get_child() returns none

gtk ComboBoxEntry.get_child() returns none

我对 gtk ComboBoxEntry 有疑问。当我尝试更改组合框中的文本时,我的程序崩溃了。我使用此代码:

   gui.combo_txt_script.get_child().set_text(fshort)

它因错误而崩溃:

AttributeError: 'NoneType' object has no attribute 'set_text'

以下打印结果:

   print "combo:",gui.combo_txt_script
   print "entry:",gui.combo_txt_script.get_child()

combo: <gtk.ComboBoxEntry object at ... >
entry: None

已更新

Gtk.ComboBox 对象的获取和设置当前值与这些对象的 model 属性相关,您可以设置 and/or 获取类似下面代码的项目:

model = combo.get_model()
value = model[combo.get_activate()][0]
# first index refers to row of list
# second index refers to cell in the row. by default an combo/combo-entry have one cell
combo.set_activate(list(model).index(value))

我发现了问题。我使用的程序有不同的用户级别。每个选项卡以及每个小部件对于每个用户级别都不可见。不知怎么的,正好用户等级可以自己改变,导致组合不存在