python实现表格控件

时间:2024-03-18 20:18:18

“”"
-- coding:utf-8 --
author:YY设计
datetime: 2019/9/22 9:55
software: PyCharm
@Email : [email protected]
学习交流qq群:916696436
“”"
import tkinter
from tkinter import ttk
win = tkinter.Tk()
win.title(‘gui’)
win.geometry(‘600x400+200+20’)
#表格
tree = ttk.Treeview(win)
tree.pack()
#定义列
tree[“columns”] = (“姓名”,“年龄”,“身高”,“体重”)
#设置列,不显示
tree.column(“姓名”,width = 100)
tree.column(“年龄”,width = 100)
tree.column(“身高”,width = 100)
tree.column(“体重”,width = 100)
#显示表头
tree.heading(“姓名”,text=“姓名——name”)
tree.heading(“年龄”,text=“姓名——name”)
tree.heading(“身高”,text=“姓名——name”)
tree.heading(“体重”,text=“姓名——name”)

#添加数据
tree.insert("",0,text=“line1”,values=(“asdha”,“20”,“165”,“70”))
tree.insert("",1,text=“line1”,values=(“a”,“20”,“165”,“70”))
tree.insert("",2,text=“line1”,values=(“a”,“20”,“165”,“70”))
tree.insert("",3,text=“line1”,values=(“aha”,“20”,“165”,“70”))
win.mainloop()
python实现表格控件