Python GUI 之 Treeview 学习
例子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()
代码运行结果:
例子2, subtrree
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=www.hjylp178.com 150,anchor='center') #指定第一列的宽度和名称, 如果show = "headings", 这一列就被隐藏。
tree.column('1',width=www.dfgjyl.cn 100,anchor='center')
tree.column('2',width=www.yongxinzaixian.cn100,anchor='w')
tree.column('3',width=100,anchor='center')
tree.column('4',width=100,anchor='center')
tree.heading('0'www.gangchengyuLe178.com ,text='column0')
tree.heading('1',text=www.ysyl157.com 'column1')
tree.heading('2',text=www.mcyllpt.com 'column2')
tree.heading('3',text=www.meiwanyule.cn 'column3')
tree.heading('4',text='column4')
#用递归法遍历带子字典或列表的数据
def process_dict(d, tree, tr):
for k,v in d.items():
if type(v) == list:
if type(v[0]) == dict:
trr www.yigouyule2.cn = tree.insert(tr, 'end', text=k, open=True)
for ls in v:
process_dict(ls, tree, trr)
else:
tree.insert(tr, 'end', text=k, values= v)
elif type(v) == dict:
trr = tree.insert(tr, 'end', text=k, open = True)
process_dict(v, tree, trr)
process_dict(data,tree, "")
tree.pack()
win.mainloop()
代码运行结果:
例子3, 添加滚动条
from tkinter import *
import tkinter.ttk as ttk
win = Tk()
win.geometry("100x100")
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"], \
"item3": ["1a", "2a", "3a", "4a"], \
"item4": {"num40": ["1n", "2n", "3n", " 4n"], "num41": ["1m", "2m", "3m", "4m"]},
"item6": ["1c", "2c", "3c", "4c"],\
"item7":["1a","2a","3a","4a"], \
"item8":{"num80":["1n", "2n", "3n"," 4n"],"num81":["1m","2m","3m","4m"]},
"item9":["1c","2c","3c","4c"],\
"item10":["1a","2a","3a","4a"], \
"item11":{"num110":["1n", "2n", "3n"," 4n"],"num111":["1m","2m","3m","4m"]},
"item12":["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')
#用递归法遍历带子字典或列表的数据
def process_dict(d, tree, tr):
for k,v in d.items():
if type(v) == list:
if type(v[0]) == dict:
trr = tree.insert(tr, 'end', text=k, open=True)
for ls in v:
process_dict(ls, tree, trr)
else:
tree.insert(tr, 'end', text=k, values= v)
elif type(v) == dict:
trr = tree.insert(tr, 'end', text=k, open = True)
process_dict(v, tree, trr)
process_dict(data,tree, "")
#y滚动条
yscrollbar = Scrollbar(win, orient=VERTICAL, command=tree.yview)
tree.configure(yscrollcommand = yscrollbar.set)
yscrollbar.pack(side = RIGHT, fill = Y)
#x滚动条
xscroll = Scrollbar(win, orient=HORIZONTAL, command=tree.xview)
tree.configure(xscrollcommand = xscroll.set)
xscroll.pack(side = BOTTOM, fill = X)
tree.pack(side = TOP, expand = 1, fill = BOTH)
win.mainloop()
代码运行结果:
---------------------
作者:weixin_41501380
来源:CSDN
原文:https://blog.csdn.net/weixin_41501380/article/details/83933484
版权声明:本文为博主原创文章,转载请附上博文链接!
Python GUI 之 Treeview 学习的更多相关文章
- Python:GUI之tkinter学习笔记1控件的介绍及使用
相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...
- Python:GUI之tkinter学习笔记之messagebox、filedialog
相关内容: messagebox 介绍 使用 filedialog 介绍 使用 首发时间:2018-03-04 22:18 messagebox: 介绍:messagebox是tkinter中的消息框 ...
- Python:GUI之tkinter学习笔记3事件绑定
相关内容: command bind protocol 首发时间:2018-03-04 19:26 command: command是控件中的一个参数,如果使得command=函数,那么点击控件的时候 ...
- Python:GUI之tkinter学习笔记2界面布局显示
相关内容: pack 介绍 常用参数 使用情况 常用函数 grid 介绍 常用参数 使用情况 常用函数 place 介绍 常用参数 使用情况 常用函数 首发时间:2018-03-04 14:20 pa ...
- python3.4学习笔记(九) Python GUI桌面应用开发工具选择
python3.4学习笔记(九) Python GUI桌面应用开发工具选择 Python GUI开发工具选择 - WEB开发者http://www.admin10000.com/document/96 ...
- 使用PyQt来编写第一个Python GUI程序
原文:使用PyQt来编写第一个Python GUI程序 本文由 伯乐在线 - Lane 翻译,Daetalus 校稿.未经许可,禁止转载!英文出处:pythonforengineers.com.欢迎加 ...
- Python GUI开发环境的搭建
原文:Python GUI开发环境的搭建 最近对Python的开发又来了兴趣,对于Python的开发一直停留在一个表面层的认识,玩的部分比较大. Python的入手简单,语法让人爱不释手,在网络通信方 ...
- python GUI实战项目——tkinter库的简单实例
一.项目说明: 本次通过实现一个小的功能模块对Python GUI进行实践学习.项目来源于软件制造工程的作业.记录在这里以复习下思路和总结编码过程.所有的源代码和文件放在这里: 链接: https:/ ...
- python GUI图形化编程-----wxpython
一.python gui(图形化)模块介绍: Tkinter :是python最简单的图形化模块,总共只有14种组建 Pyqt :是python最复杂也是使用最广泛的图形化 Wx ...
随机推荐
- fiddler+willow问题总结
本文纯属用来记录自己学习过程中遇到的坑,如有朋友也遇到,可移步到这里查看是否为该问题导致. fiddler 安装不用说了,到官网直接去下载,自行下载最新版本 willow下载地址:http://qzo ...
- Dijkstra算法——单源最短路算法
一.介绍 迪杰斯特拉(Dijkstra)算法是典型最短路径算法,用于计算一个节点到其他各个节点的最短路径. 它的主要特点是以起始点为中心向外层层扩展(广度优先搜索思想),直到扩展到终点为止. 适用于有 ...
- JS 、JQ 获取宽高总结 & JS中getBoundingClientRect的作用及兼容方案
1.getBoundingClientRect的作用 getBoundingClientRect用于获取某个html元素相对于视窗的位置集合. 执行 object.getBoundingClien ...
- 讲课笔记3——浮动、margin失效的问题、默认样式重置
EO:搜索引擎优化,一般在网页里面只写一个h1标签,搜索引擎可以通过该h1标签里面的内容搜索你所写的网页(a标签和img标签最好写上title属性)标准写法: .logo { text-decorat ...
- 【iview input 回车刷页面bug】input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-show false 就可以了
[iview input 回车刷页面bug]input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-sh ...
- caffe修改需要的东西 6:40
https://blog.csdn.net/zhaishengfu/article/details/51971768?locationNum=3&fps=1
- myeclipse 导入项目时no projects are found to import解决办法
myeclipse 识别一个工程需要.classpath与.project文件,一般无需提交SVN所以项目切下来的时候是没有这两个文件的. 方法1: 1) 在myeclipse中新建一个和你要导入的项 ...
- UEditor1.4.3的实例程序
官网:http://ueditor.baidu.com/website/ 配置下就可以使用 (1)下载,解压后文件结构如下: (2)将整个文件夹改名ueditor后复制到WebRoot目录下: (3) ...
- oracle row_number的使用
create table studentInfo( id number(8) primary key, name varchar2(20) not null, ObjectName varcha ...
- css flew 布局 解决父元素高度不固定,子级居中。
给父级添加 display: flex; justify-content: flex-start; align-items: center; 子级里的内容永远居中