我正在尝试按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"),(""))))
我知道我可以重新排列.insert
行,但这只是一个例子。
理想情况下,也许是按照Treeview.reorder("Patrols",(A-Z))