gpt4 book ai didi

gtk - PyGtk:如何对与 CellRendererCombo 关联的列表存储中的项目进行排序

转载 作者:行者123 更新时间:2023-12-02 02:12:27 24 4
gpt4 key购买 nike

如何对附加到 CellRendererCombo 的 ListStore 中的项目进行排序

cellrenderer_combo = gtk.CellRendererCombo()
...
liststore = gtk.ListStore(str)
item_list = ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6"]
for item in item_list:
liststore.append([item])

self.cellrenderer_combo.set_property("model", self.liststore)

如何按降序对 Liststore 中的“项目”进行排序???

提前致谢。 :)

最佳答案

如果项目不会改变,那么在将它们添加到列表存储之前只需对它们进行排序:

item_list = ['These', 'items', 'are', 'not', 'going', 'to', 'change']
item_list.sort(reverse=True)

如果项目要更改并且您希望在组合框中对它们进行排序,则使用 gtk.TreeModelSort :

sorted = gtk.TreeModelSort(liststore)
self.cellrenderer_combo.props.model = self.liststore

关于gtk - PyGtk:如何对与 CellRendererCombo 关联的列表存储中的项目进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12159765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com