Python 3.3.2 tkinter ttk TreeView per-column sorting only sorts by last column? Python 3.3.2 tkinter ttk TreeView per-column sorting only sorts by last column? tkinter tkinter

Python 3.3.2 tkinter ttk TreeView per-column sorting only sorts by last column?


You should use lambda in other way. In your code every lambda gets a pointer to the same variable, that is why all functions do the same thing. You should, e.g, copy variable to make lambda unique. An example how to do it:

for each in ('name', 'path', 'time','pb'):    listbox.heading(each,text=each.capitalize(),command=lambda each_=each: treeview_sort_column(listbox, each_, False))

Simple example:

funcs = []for item in ('abc', 'def', 'ghi'):    funcs.append(lambda : print(item))for f in funcs:    f()

It prints:

ghighighi

But version with fixed lambda:

funcs = []for item in ('abc', 'def', 'ghi'):    funcs.append(lambda item_=item: print(item_))for f in funcs:    f()

prints

abcdefghi