Python:gtk.ComboBox 追加框

标签 python combobox gtk append vbox

案例如下: 我想将多个 gtk.VBox()'es append 到 gtk.ComboBox。 还没有找到方法,但搜索了很长一段时间。

提前致谢

编辑:我想要达到的主要目的是获取除组合框中文本之外的图像。 谢谢。

最佳答案

您可以像在 TreeView 中一样将 CellRendererPixbuf 添加到 ComboBox:

model = gtk.ListStore(gtk.gdk.Pixbuf, str)
model.append([gtk.gdk.pixbuf_new_from_file('image.png'), 'Foo'])

cb = gtk.ComboBox(model)

pb_cell = gtk.CellRendererPixbuf()
cb.pack_start(pb_cell, False)
cb.add_attribute(pb_cell, 'pixbuf', 0)

txt_cell = gtk.CellRendererText()
cb.pack_start(txt_cell, True)
cb.add_attribute(txt_cell, 'text', 1)

关于Python:gtk.ComboBox 追加框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553425/

相关文章:

python - 字符串是如何比较的?

python - 从 Python 中的生成器创建一个 zip 文件?

WPF MVVM : Add item not present in combobox

mysql - 创建 gtk ListView 时出错

python - 如何真正将窗口置于所有窗口之上——Linux PyGTK

rust - 使用 Rust 在 GTK GUI 上渲染小的 LaTeX 片段

python - 如何使用 python flask 从谷歌云存储服务图像

php - 将 html 组合框值传递给同一文件中的 php 而无需提交

c# - 在 C# 中输入 ComboBox

python - Django 休息 + Jinja2 : ValueError: dictionary update sequence element #0 has length 0; 2 is required