带有cellRenderTogg的Gtk3 python组合框

2024-06-08 23:53:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个带有复选框的组合框的Gtk。但是“我的”复选框是不活动的,尽管我尝试了很多方法-我只是不能点击它们。这是我程序的一个片段

self.listst= Gtk.ListStore(str)
combost= Gtk.ComboBox.new_with_model(self.listst)
self.rend = Gtk.CellRendererToggle()
self.rend.connect("toggled", self.cell_toggled)        
combost.pack_start(self.rend, False)
for stac in ["first option","second option"]:
    self.listst.append([stac])
cellrendst = Gtk.CellRendererText()
combost.pack_start(cellrendst, True)
combost.add_attribute(cellrendst, "text", 0)
self.buttbox.pack_start(combost,True, True,0)


def cell_toggled(rend, path):
    self.rend[path][1] = not self.rend[path][1]

我想我必须将这个cellRenderToggle()打包,并设置cellRenderToggle的活动状态,但我不知道如何将它加入combobox。你知道吗


Tags: pathselftruegtkcellstartpack复选框