【发布时间】:2018-05-27 23:02:34
【问题描述】:
我有一个用 tkinter 制作的简单树视图。是否可以在 tkinter treview 中制作一个网格,使其看起来更像一张表格?
我想让它更“用户友好”,这样表格/树视图的可视化会更好。
from tkinter import *
from tkinter import ttk
myApp = Tk()
myApp.title(" Program ")
myApp.geometry("800x700")
tree = ttk.Treeview(myApp,height=25)
tree['show'] = 'headings'
sb = ttk.Scrollbar(myApp, orient="vertical", command=tree.yview)
sb.grid(row=1,column=1,sticky="NS",pady=5)
tree.configure(yscrollcommand=sb.set)
tree["columns"]=("1","2","3")
tree.column("1", width=50)
tree.column("2", width=50)
tree.column("3", width=50)
tree.heading("1", text="Col 1")
tree.heading("2", text="Col 2")
tree.heading("3", text="Col 3")
item = tree.insert("", "end", values=("",))
tree.grid(row=1,column=0,padx=5,pady=5)
myApp.mainloop()
【问题讨论】: