Python GUI 之 Treeview 学习

Python的Treeview手册  https://docs.python.org/3.1/library/tkinter.ttk.html?highlight=treeview#tkinter.ttk.Treeview

一个不错的博客文章 https://blog.csdn.net/sinat_27382047/article/details/80161637

按列内的值进行排序

https://stackoverflow.com/questions/1966929/tk-treeview-column-sort

https://stackoverflow.com/questions/22032152/python-ttk-treeview-sort-numbers/46712710

例子1

from tkinter import *
import tkinter.ttk as ttk

win = Tk()
win.title("Treeview 学习")

col = [1,2,3,4]
data = {"item0":["1a","2a","3a","4a"], "item1":{"num0":["1n", "2n", "3n"," 4n"],"num1":["1m","2m","3m","4m"]}, "item2":["1c","2c","3c","4c"]}

tree = ttk.Treeview(win, columns = col, height = 10, show = "tree")
#show = "tree", 第一列也会被显示出来
#也可用show = "headings" 把第一列隐藏起来
#height 的单位是字符,本例里可以显示10行

tree.column('0',width=150,anchor='center')   #指定第一列的宽度和名称, 如果show = "headings", 这一列就被隐藏。
tree.column('1',width=100,anchor='center')
tree.column('2',width=100,anchor='w')
tree.column('3',width=100,anchor='center')
tree.column('4',width=100,anchor='center')
tree.heading('0',text='column0')
tree.heading('1',text='column1')
tree.heading('2',text='column2')
tree.heading('3',text='column3')
tree.heading('4',text='column4')

tree.insert('','end',values= data["item0"])
tree.insert('','end',values= data["item2"])

tree.pack()

win.mainloop()

代码运行结果:

  • 14
    点赞
  • 126
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值