【问题标题】:PyGObject Problems with a ComboBoxEntry组合框条目的 PyGObject 问题
【发布时间】:2014-06-14 22:49:09
【问题描述】:

ComboBoxEntry 和填充它的函数有问题。

这是 GUI 上的 __init__ 代码。

self.combobox_category = self.builder.get_object("combobox_category")
self.combobox_category.set_entry_text_column(1)
INIT_COMBOBOX_category(self)

这是填充ComboBoxEntry 的函数。

def INIT_COMBOBOX_category(self):

    self.list_category = Gtk.ListStore(int,str)
    self.list_category.clear()

    self.list_category.append([0,"< List all the categories >"])
    self.list_category.append([1,"No specified"])

    #...No relevant code...

    self.combobox_category.set_model(self.list_category)
    self.cell = Gtk.CellRendererText()
    self.combobox_category.pack_start(self.cell, True)
    self.combobox_category.add_attribute(self.cell, 'text', 1)
    self.combobox_category.set_active(1)

问题是当我启动 GUI 时,combobox_category 有“重复值” (仅在选择值时,不在ComboBoxEntry 中):

< List all the categories > < List all the categories >
No specified                No specified

然后,当我需要再次使用函数INIT_COMBOBOX_category(self) 时,值会增加三倍,等等。

我认为

self.list_category.clear()

不工作。

奇怪的是,在 Glade 中,我选择了 ComboBoxEntry 为“可编辑”,我不能在上面写字。我也试过“覆盖模式”,还是不行!

【问题讨论】:

    标签: python gtk glade pygobject


    【解决方案1】:

    我找到了一个解决方案,它包括在 python 中而不是 glade 中创建 ComboBoxEntry,在 init 函数中创建 ComboBoxEntry,并在 INIT_COMBOBOX_category 中修改 ListStore。

    init 代码如下:

    self.list_category=Gtk.ListStore(int,str)
    self.category_combo=Gtk.ComboBox.new_with_model_and_entry(self.list_category)
    self.category_combo.show()
    self.box_category_to_install.add(self.category_combo)
    self.category_combo.set_entry_text_column(1)
    INIT_COMBOBOX_category(self)
    

    (我在空地中添加了一个名为 box_category_to_install 的盒子来放置 ComboBoxEntry )

    def INIT_COMBOBOX_category(self):
    
        self.list_category.clear()
        self.list_category.append([0,"< List all the categories >"])
        self.list_category.append([1,"No specified"])
        etc...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-20
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 2011-03-30
      • 2011-11-25
      相关资源
      最近更新 更多