Tkinter Treeview Column Sorting
@Mayur had the right idea, just missed including the definition of treeview_sort_column
. I can vouch for the technique, though I implemented the call differently than the command option. You can review it at this link as well (though it may die in the future)
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))[...]