我想知道如何证明 ttk.Treeview 列中的文本。下面是我的意思的一个例子。请注意日期以及数字如何不正确地在彼此之下。我认为这与间距有关,但我可能是错的。
编辑:它是用 Python 3 编写的。
#! coding=utf-8
import pickle
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import ttk
# Create Example
root = tk.Tk()
root.minsize(200,300)
tree = ttk.Treeview(root,columns=("date"))
tree.heading("#0" , text='Sample', anchor=tk.W)
tree.column("#0", stretch=0)
tree.heading("date", text='Date', anchor=tk.E)
tree.column("date", stretch=0)
ABC = ["A","B","C","D","E"]
dates = ["3.4.2013", "14.10.400", "24.12.1234", "1.10.1", "14.7.123"]
tree.insert("",iid="1", index="end",text="No Format")
for i in range(len(ABC)):
dates2 = dates[i].split(".")
date = "{:<2}.{:<2}.{:<4}".format(dates2[0],dates2[1],dates2[2])
tree.insert("1",iid="1"+str(i), index="end",text=ABC[i], value=[dates[i]])
tree.see("14")
tree.insert("",iid="2", index="end",text="With Format")
for i in range(len(ABC)):
dates2 = dates[i].split(".")
date = "{:>2}.{:>2}.{:>4}".format(dates2[0],dates2[1],dates2[2])
tree.insert("2",iid="2"+str(i), index="end",text=ABC[i], value=[date])
tree.see("24")
tree.pack(expand=True,fill=tk.BOTH)
root.mainloop()