【问题标题】:Creating Simple PyGTK ComboBox Causes Error创建简单的 PyGTK ComboBox 导致错误
【发布时间】: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

【问题讨论】:

    标签: python gtk pygtk


    【解决方案1】:

    正如错误告诉你的那样,gtk.ComboBox 中没有 new_with_model() 方法。请参阅documentation

    改为使用comboBox = gtk.ComboBox(model=client_store)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-30
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 2019-04-16
      • 2018-12-22
      • 2014-05-16
      • 1970-01-01
      相关资源
      最近更新 更多