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 ...
随机推荐
- 【extjs6学习笔记】0.2 准备:类库结构
- iOS上线check_list
iOS 上线前 check_list 类型 序号 检查项 结果(pass/no) 安装 卸载 1 非越狱环境下的安装.卸载 2 越狱环境下的安装.卸载 3 安装文件检查,无泄漏用户信息的隐患 4 卸载 ...
- MySQL存储过程(批量生成论坛中发帖、回帖、主题等数据)
USE 数据库名称1;DROP PROCEDURE IF EXISTS 数据库名称1.存储过程名称;delimiter $$CREATE PROCEDURE 数据库名称1.存储过程名称(in v_co ...
- 你是猴子请来的逗比么!IT跳槽大事件
3月招聘大战早已硝烟四起,互联网职场摇身一变成了跳蚤市场,猎头们告诉跳蚤们,跳不跳不是不问题,往哪儿跳才是重点,跳对了高薪期权都如过眼云烟.不过小编不得不说,劳资最痛恨那些跳槽的人啦!就因为加班 ...
- 一个制作Xcode5插件的模板
原Github地址:https://github.com/kattrali/Xcode5-Plugin-Template 安装将 本工成复制到~/Library/Developer/Xcode/Tem ...
- eclipse中Lombok注解无效
问题现象:eclipse中使用lombok的@Date,引用get方法时,报错. 解决方案: 在lombok官网(https://www.projectlombok.org/download)下载,或 ...
- 量化投资,你需要了解的A股财务数据
摘要:基本面量化是应用量化研究领域的重头戏,财务数据的整理和加工是基本面量化的第一步.本文梳理了财务数据的基本知识,包括报表类型.数据来源.调整更正和使用原则等,并给出了单季度和TTM数据的计算流程. ...
- Open Scene Graph:让VS支持不含后缀的头文件
让VS支持不含后缀的头文件 看OSG源码时,会遇到不含后缀的头文件无定位信息的尴尬,很让人苦恼. 就是单击VS中“工具菜单栏”——>”选项(O)….”如下图所示: 菜单项,弹出选项对话框,单击“ ...
- java POI技术之导出数据优化(15万条数据1分多钟)
专针对导出excel2007 ,用到poi3.9的jar package com.cares.ynt.util; import java.io.File; import java.io.FileOut ...
- 配置SpringMVC返回JSON遇到的坑
坑一:官方网站下载地址不明朗,最后找了几个下载地址:http://wiki.fasterxml.com/JacksonDownload Jackson2.5下载地址:jackson2.5.0.jar ...