python tkinter treeview制作,Python tkinter之Treeview(表格)

1、Treeview的基本属性

# -*- encoding=utf-8 -*-

import tkinter

from tkinter import *

from tkinter import ttk

if __name__ == '__main__':

pass

win = tkinter.Tk() # 窗口

win.title('南风丶轻语') # 标题

screenwidth = win.winfo_screenwidth() # 屏幕宽度

screenheight = win.winfo_screenheight() # 屏幕高度

width = 1000

height = 500

x = int((screenwidth - width) / 2)

y = int((screenheight - height) / 2)

win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 大小以及位置

columns = ['学号', '姓名', '性别', '出生年月', '籍贯', '班级']

table = ttk.Treeview(

master=win, # 父容器

height=10, # 高度,可显示height行

columns=columns, # 显示的列

show='headings'

)

table.heading('学号', text='学号', ) # 定义表头

table.heading('姓名', text='姓名', ) # 定义表头

table.heading('性别', text='性别', ) # 定义表头

table.heading('出生年月', text='出生年月', ) # 定义表头

table.heading('籍贯', text='籍贯', ) # 定义表头

table.heading('班级', text='班级', ) # 定义表头

table.column('学号', width=100, anchor=S) # 定义列

table.column('姓名', width=150, anchor=S) # 定义列

table.column('性别', width=50, anchor=S) # 定义列

table.column('出生年月', width=150, anchor=S) # 定义列

table.column('籍贯', width=150, anchor=S) # 定义列

table.column('班级', width=150, anchor=S) # 定义列

table.pack(pady=20)

win.mainloop()

ba54527cd8d00d3bbae8fb3da82959e5.png

备注:

①heading 定义显示的表头

②column 定义显示的列,width为列宽度,anchor为对齐方式,可选项为:n, ne, e, se, s, sw, w, nw, center

2、插入数据到表格中

# -*- encoding=utf-8 -*-

import tkinter

from tkinter import *

from tkinter import

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值