I have a MultiBoxList from TkinterTreeCtrl in a window with multiple columns, some are numeric, some alphabetical (I believe as far as this cares, they're all alphanumeric). This has been populated from a database.
I would like to be able to click the column headers to either: switch which column is being used to sort the list, or: reverse the sort order (i.e. descending ascending) if that column is already being used to sort.
Below is an outline of one of these lists.
from tkinter import *
from tkinter import ttk
import TkTreectrl as treectrl
root = Tk()
root.title("Columns Demo")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
# ========== Pickers Panel =============
top_panel = ttk.Frame(mainframe, padding="3 3 12 12")
top_panel.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
demo_picker_vscroll = ttk.Scrollbar(top_panel)
demo_picker_hscroll = ttk.Scrollbar(top_panel, orient='horizontal')
demo_picker_vscroll.grid(column=1, row=1, sticky=(N, W, S))
demo_picker_hscroll.grid(column=0, row=2, sticky=(N, W, E))
demo_picker_label = ttk.Label(top_panel, text="Table:", anchor=CENTER)
demo_picker_label.grid(column=0, row=0, sticky=(W, E))
demo_picker = treectrl.MultiListbox(top_panel, yscrollcommand=demo_picker_vscroll.set,
xscrollcommand=demo_picker_hscroll.set)
demo_picker.focus_set()
demo_picker.configure(selectcmd=None, selectmode="single", width=300, height=200)
demo_picker.config(columns=("Column1", "Column2"))
demo_picker.column_configure(0, width=200)
demo_picker.grid(column=0, row=1, sticky=(W, E, S, N))
demo_picker_vscroll.config(command=demo_picker.yview)
demo_picker_hscroll.config(command=demo_picker.xview)
for i, row in enumerate(range(50)):
demo_picker.insert(i, i, row)
root.mainloop()
In my actual use case one of these columns could contain assorted strings not just numbers, others may be timestamps, so sorting them becomes very needed.
Further, I have a date
column in one of my panels like this. Is there a particular datetime formatting that's still human readable but will obey sensible ordering? YYY-MM-DD HH:MM:SS
should work for this right?
Lastly as a side question, can I make the text from these copy-pastable?