通过一列按字母顺序排列ttk.treeview表

时间:2018-12-02 15:30:44

标签: python tkinter ttk

我正在尝试按Patrol组织此Treeview小部件,以便按Patrol列的字母顺序对其进行排序。

这是示例代码:

import tkinter as tk
from tkinter import messagebox
from tkinter.font import Font
from tkinter import scrolledtext
from tkinter import ttk


# AttendanceView Specific Table Components
Attendance=tk.Tk()
AttendanceView = ttk.Treeview(Attendance)
AttendanceView["columns"] = ("firstname", "secondname","patrol","present")
AttendanceView.grid(row=3, column=1)
AttendanceView.heading("#0", text="", anchor="w")
AttendanceView.column("#0", anchor="center", width=5, stretch=tk.NO)
AttendanceView.heading("firstname", text="First Name", anchor="w")
AttendanceView.column("firstname", anchor="center", width=80)
AttendanceView.heading("secondname", text="Second Name", anchor="w")
AttendanceView.column("secondname", anchor="center", width=90)
AttendanceView.heading("patrol", text="Patrol", anchor="w")
AttendanceView.column("patrol", anchor="center", width=80)
AttendanceView.heading("present", text="Present", anchor="w")
AttendanceView.column("present", anchor="center", width=80)
AttendanceView.grid(row=3, column=1, columnspan=5)

AttendanceViewScrollbar = ttk.Scrollbar(Attendance, orient="vertical", command=AttendanceView.yview)
AttendanceView.configure(yscroll=AttendanceViewScrollbar.set)
AttendanceViewScrollbar.grid(row=3, column=6, sticky="ns")

AttendanceView.insert("", "end", text="", values=(("Bobby",("Kennedy"),("Zebra"),(""))))
AttendanceView.insert("", "end", text="", values=(("Ethel",("Kennedy"),("Cow"),(""))))
AttendanceView.insert("", "end", text="", values=(("Jack",("Kennedy"),("Lion"),(""))))

当前输出如下所示: Current Result

所需的输出如下所示: Desired Result

我知道我可以重新排列.insert行,但这只是一个例子。 理想情况下,也许是按照Treeview.reorder("Patrols",(A-Z))

的解决方案

0 个答案:

没有答案