插入方法:
import tkinter
from tkinter import ttk # 导入内部包
li = ['王记','12','男']
root = tkinter.Tk()
root.title('测试')
tree = ttk.Treeview(root,columns=['1','2','3'],show='headings')
tree.column('1',width=100,anchor='center')
tree.column('2',width=100,anchor='center')
tree.column('3',width=100,anchor='center')
tree.heading('1',text='姓名')
tree.heading('2',text='学号')
tree.heading('3',text='性别')
tree.insert('','end',values=li)
tree.grid()
root.mainloop()
代码来自博客园提问:https://q.cnblogs.com/q/105829/#a_226277
tree.insert('','end',values=li)
关于“首列很宽”的问题:https://segmentfault.com/q/1010000004206667?sort=created
设置show属性为 headings 即可隐藏首列。
ttk.Treeview(frame,height=18, show="headings", columns=('a','b','c','d','e','f'))
配上一个还可以的综合一点的例子https://www.cnblogs.com/Tommy-Yu/p/4156014.html
清空方法:
参考stackoverflow的提问https://stackoverflow.com/questions/32511843/delete-and-edit-items-in-treeview-tkinter
代码是对上面的代码添加:
importtkinterfrom tkinter import