def __init__(self, master):
super().__init__()
self.title("Log")
self.geometry("600x300")
self.notebook = ttk.Notebook(self)
self.tab_trees = {}
style = ttk.Style()
style.configure("Treeview", font=(None,12))
style.configure("Treeview.Heading", font=(None, 14))
dates = self.master.get_unique_dates()
for index, date in enumerate(dates):
dates[index] = date[0].split()[0]
dates = sorted(set(dates), reverse=True)
for date in dates:
tab = tk.Frame(self.notebook)
columns = ("name", "finished", "time")
tree = ttk.Treeview(tab, columns=columns, show="headings")
tree.heading("name", text="Name")
tree.heading("finished", text="Full 25 Minutes")
tree.heading("time", text="Time")
tree.column("name", anchor="center")
tree.column("finished", anchor="center")
tree.column("time", anchor="center")
tasks = self.master.get_tasks_by_date(date)
for task_name, task_finished, task_date in tasks:
task_finished_text = "Yes" if task_finished else "No"
task_time = task_date.split()[1]
task_time_pieces = task_time.split(":")
task_time_pretty = "{}:{}".format(task_time_pieces[0], task_time_pieces[1])
tree.insert("", tk.END, values=(task_name, task_finished_text, task_time_pretty))
tree.pack(fill=tk.BOTH, expand=1)
tree.bind("<Double-Button-1>", self.confirm_delete)
self.tab_trees[date] = tree
self.notebook.add(tab, text=date)
self.notebook.pack(fill=tk.BOTH, expand=1)
python类Treeview()的实例源码
def __init__(self, master):
super().__init__()
self.title("Log")
self.geometry("600x300")
self.notebook = ttk.Notebook(self)
dates_sql = "SELECT DISTINCT date FROM pymodoros ORDER BY date DESC"
dates = self.master.runQuery(dates_sql, None, True)
for index, date in enumerate(dates):
dates[index] = date[0].split()[0]
dates = sorted(set(dates), reverse=True)
for date in dates:
tab = tk.Frame(self.notebook)
columns = ("name", "finished", "time")
tree = ttk.Treeview(tab, columns=columns, show="headings")
tree.heading("name", text="Name")
tree.heading("finished", text="Full 25 Minutes")
tree.heading("time", text="Time")
tree.column("name", anchor="center")
tree.column("finished", anchor="center")
tree.column("time", anchor="center")
tasks_sql = "SELECT * FROM pymodoros WHERE date LIKE ?"
date_like = date + "%"
data = (date_like,)
tasks = self.master.runQuery(tasks_sql, data, True)
for task_name, task_finished, task_date in tasks:
task_finished_text = "Yes" if task_finished else "No"
task_time = task_date.split()[1]
task_time_pieces = task_time.split(":")
task_time_pretty = "{}:{}".format(task_time_pieces[0], task_time_pieces[1])
tree.insert("", tk.END, values=(task_name, task_finished_text, task_time_pretty))
tree.pack(fill=tk.BOTH, expand=1)
self.notebook.add(tab, text=date)
self.notebook.pack(fill=tk.BOTH, expand=1)
def __init__(self, parent, *args, **kwargs):
ttk.Treeview.__init__(self, parent, selectmode="browse", columns=["File Extension",
"Date Modified",
"File Type",
"Compress Type",
"Comment",
"Extra",
"Create System",
"Create Version",
"Extract Version",
"Reserved",
"Flag Bits",
"Volume",
"Internal Attr",
"External Attr",
"Header Offset",
"CRC",
"Compress Size",
"File Size",
"Filler"], *args, **kwargs)
self.heading("#0", text="File Name")
self.column("#0", width=200, stretch=False)
self.heading("#1", text="File Extension")
self.column("#1", width=80, stretch=False)
self.heading("#2", text="Date Modified")
self.column("#2", width=100, stretch=False)
self.heading("#3", text="File Type")
self.column("#3", width=80, stretch=False)
self.heading("#4", text="Compress Type")
self.column("#4", width=100, stretch=False)
self.heading("#5", text="Comment")
self.column("#5", width=80, stretch=False)
self.heading("#6", text="Extra")
self.column("#6", width=60, stretch=False)
self.heading("#7", text="Create System")
self.column("#7", width=100, stretch=False)
self.heading("#8", text="Create Version")
self.column("#8", width=100, stretch=False)
self.heading("#9", text="Extract Version")
self.column("#9", width=100, stretch=False)
self.heading("#10", text="Reserved")
self.column("#10", width=100, stretch=False)
self.heading("#11", text="Flag Bits")
self.column("#11", width=100, stretch=False)
self.heading("#12", text="Volume")
self.column("#12", width=100, stretch=False)
self.heading("#13", text="Internal Attr")
self.column("#13", width=100, stretch=False)
self.heading("#14", text="External Attr")
self.column("#14", width=100, stretch=False)
self.heading("#15", text="Header Offset")
self.column("#15", width=100, stretch=False)
self.heading("#16", text="CRC")
self.column("#16", width=100, stretch=False)
self.heading("#17", text="Compress Size")
self.column("#17", width=90, stretch=False)
self.heading("#18", text="File Size")
self.column("#18", width=70, stretch=False)
self.column("#19", width=1)