Tk 树视图列排序

2023-12-27

有没有办法对 a 中的条目进行排序Tk 树视图 http://www.tkdocs.com/tutorial/tree.html通过单击该列?令人惊讶的是,我找不到任何相关文档/教程。


帕特霍伊茨 http://www.patthoyts.tk/ from #tcl指出 TreeView Tk 演示程序具有排序功能。这是它的 Python 等效项:

def treeview_sort_column(tv, col, reverse):
    l = [(tv.set(k, col), k) for k in tv.get_children('')]
    l.sort(reverse=reverse)

    # rearrange items in sorted positions
    for index, (val, k) in enumerate(l):
        tv.move(k, '', index)

    # reverse sort next time
    tv.heading(col, command=lambda: \
               treeview_sort_column(tv, col, not reverse))

[...]
columns = ('name', 'age')
treeview = ttk.TreeView(root, columns=columns, show='headings')
for col in columns:
    treeview.heading(col, text=col, command=lambda: \
                     treeview_sort_column(treeview, col, False))
[...]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tk 树视图列排序 的相关文章

随机推荐