Я пытаюсь отсортировать значение по времени окончания, но все равно не получилось.См. Изображение ниже! [https://drive.google.com/file/d/1N0uAnOyHHsfw2Q_SIiEDnZ7fPc6v_IcQ/view?usp=sharing]
Я ожидал, что столбец времени окончания будет отсортирован в порядке возрастания.
def treeview_sort_column(tv, col, reverse):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
l.sort(key=lambda t: int(t[0]), 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))
def showresult():
global result_screen
ga_screen = Toplevel(screen)
ga_screen.title('detail result')
tree = ttk.Treeview(ga_screen)
ysb = ttk.Scrollbar(tree, orient='vertical', command=tree.yview)
xsb = ttk.Scrollbar(tree, orient='horizontal', command=tree.xview)
tree.configure(yscroll=ysb.set, xscroll=xsb.set)
tree["columns"]=("two",'three','four')
tree.column("#0", width=100)
tree.column("two", width=100)
tree.column('three', width=100)
tree.column('four', width=100)
tree.heading("#0", text="job number")
tree.heading("two", text="process time",command=lambda:
treeview_sort_column(tree,'two', False))
tree.heading("three", text="finish time",command=lambda:
treeview_sort_column(tree,'three', False))
tree.heading("four", text="due date",command=lambda:
treeview_sort_column(tree,'four', False))
for i in range(len(l_best)):
prc_choosen = 0
print('machine number:',i+1)
for k in range(num_job):
if k%mch_num_info ==i:
prc_choosen=prc_choosen+p[sequence_best[k][0]][sequence_best[k][1]]
print('job no', l[sequence_best[k][0]][sequence_best[k][1]],'prc time:',p[sequence_best[k][0]][sequence_best[k][1]]
,'flow time:',prc_choosen,'due date:',d[sequence_best[k][0]][sequence_best[k][1]])
for i in range(len(l_best)):
prc_choosen = 0
tree.insert("" , i,f'machine {i}', text=f"machine {i+1}")
for k in range(num_job):
if k%mch_num_info ==i:
prc_choosen=prc_choosen+p[sequence_best[k][0]][sequence_best[k][1]]
tree.insert(f'machine {i}', i, text=f"job {l[sequence_best[k][0]][sequence_best[k][1]]}",
values=(f"{p[sequence_best[k][0]][sequence_best[k][1]]}",
f"{prc_choosen}",
f'{d[sequence_best[k][0]][sequence_best[k][1]]}'))
tree.pack()