I\'m trying to use the ttk.Treeview sort function illustrated in the answer to this question (Tk treeview column sort) and it works just fine for strings like \'abc\', \'bcd
I figure I'd add this bit of code for anyone wanting to use the above solution for both regular string sorts and numeric sorts.
def treeview_sort_column(tv, col, reverse):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
try:
l.sort(key=lambda t: int(t[0]), reverse=reverse)
# ^^^^^^^^^^^^^^^^^^^^^^^
except ValueError:
l.sort(reverse=reverse)
for index, (val, k) in enumerate(l):
tv.move(k, '', index)
tv.heading(col, command=lambda: treeview_sort_column(tv, col, not reverse))