【发布时间】:2014-03-28 14:09:34
【问题描述】:
我正在尝试创建一个简单的 PyGTK ComboBox。但是当我运行我的代码时,我得到一个运行时错误:
'comboBox = gtk.ComboBox.new_with_model(client_store)'
AttributeError: type object 'gtk.ComboBox' has no attribute 'new_with_model'
如何创建 PyGTK 组合框? 创建我发现的其中一个小部件是一个非常棘手的过程。注意我在 Python 2.7 上使用 PyGTK 2.24 版
任何关于如何创建简单 ComboBox 的建议将不胜感激。
import pygtk
pygtk.require('2.0')
import gtk
gtk.rc_parse('themes/Elegant Brit/gtk-2.0/gtkrc')
def create_combo_box(self):
client_store = gtk.ListStore(str)
for f in ("a","b","c"):
client_store.append([f])
comboBox = gtk.ComboBox.new_with_model(client_store) # Error occurs here
renderer_text = gtk.CellRendererText()
comboBox.pack_start(renderer_text, True)
comboBox.add_attribute(renderer_text, "text", 0)
return comboBox
【问题讨论】: