[英]Creating a grid lines inside of tkinter treeview
I have one simple treeview made in tkinter. 我在tkinter中制作了一个简单的treeview。 Is it possible to make a grid inside the tkinter treview, so that it looks more like a table? 是否可以在tkinter treview内制作网格,使其看起来更像一张桌子?
I want to make it more "user-friendly", so visualization of the table/treeview can be better. 我想使其更加“用户友好”,因此表/树视图的可视化效果会更好。
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()
I believe that the only option to make it more "user-friendly" is to create alternating row colors: 我相信,使其更“用户友好”的唯一选择是创建交替的行颜色:
tree.insert("", "end", values=("a",),)
tree.insert("", "end", values=("b",), tag='gray')
tree.insert("", "end", values=("c",),)
tree.insert("", "end", values=("d",), tag='gray')
tree.tag_configure('gray', background='#cccccc')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.