当前位置:   article > 正文

tkinter函数03_tree = ttk.treeview(win)

tree = ttk.treeview(win)

树状结构

#建立树状的目录
tree=ttk.Treeview(win)
tree.pack()

#添加一级树枝
treeF1=tree.insert("",0,"中国",text="中国CHI",values=("F1"))
treeF2=tree.insert("",1,"美国",text="美国USA",values=("F2"))
treeF3=tree.insert("",2,"英国",text="中国ENG",values=("F3"))

#添加F1的二级树枝
treeF1_1=tree.insert(treeF1,0,"黑龙江",text="中国黑龙江",values=("F1_1"))
treeF1_2=tree.insert(treeF1,1,"河南",text="中国河南",values=("F1_2"))
treeF1_3=tree.insert(treeF1,2,"河北",text="中国河北",values=("F1_3"))

#添加F2的二级树枝
treeF2_1=tree.insert(treeF2,0,"华盛顿",text="美国华盛顿",values=("F2_1"))
treeF2_2=tree.insert(treeF2,1,"纽约",text="美国纽约",values=("F2_2"))
treeF2_3=tree.insert(treeF2,2,"旧金山",text="美国旧金山",values=("F2_3"))

#添加三级树枝
treeF1_1_1=tree.insert(treeF1_1,0,"哈尔滨",text="黑龙江哈尔滨",value=("F1_1_1"))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

相对布局


label=tkinter.Label(win,text="good",bg="blue")
labe2=tkinter.Label(win,text="nice",bg="yellow")
labe3=tkinter.Label(win,text="cool",bg="green")

#相对布局  窗口变化对控件位置有影响
#tkinter.BOTH
label.pack(fill=tkinter.Y,side=tkinter.LEFT)
labe2.pack(fill=tkinter.X,side=tkinter.TOP)
labe3.pack(fill=tkinter.X,side=tkinter.BOTTOM)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

绝对布局

label=tkinter.Label(win,text="good",bg="blue")
labe2=tkinter.Label(win,text="nice",bg="yellow")
labe3=tkinter.Label(win,text="cool",bg="green")

#绝对布局  窗口变化对位置没有影响
label.place(x=10,y=10)
labe2.place(x=50,y=60)
labe3.place(x=100,y=100)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

表格布局

label=tkinter.Label(win,text="good",bg="blue")
labe2=tkinter.Label(win,text="nice",bg="yellow")
labe3=tkinter.Label(win,text="cool",bg="green")
labe4=tkinter.Label(win,text="handsome",bg="red")
#表格布局
label.grid(row=0,column=0)
labe2.grid(row=1,column=0)
labe3.grid(row=0,column=1)
labe4.grid(row=1,column=1)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

表格数据

tree=ttk.Treeview(win)
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="年龄-age")
tree.heading("身高",text="身高-height")
tree.heading("体重",text="体重-weight")

#添加数据
tree.insert("",0,text="line1",value=("小仓娃","24","175","54"))
tree.insert("",2,text="line2",value=("小仓","23","176","55"))
tree.insert("",1,text="line3",value=("仓","24","175","53"))
tree.insert("",3,text="line4",value=("仓娃","23","175","54"))
tree.pack()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/718703
推荐阅读
相关标签
  

闽ICP备14008679号