首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python: Treeview Control binding data using tkinter and ttkbootstrap GUI

python: Treeview Control binding data using tkinter and ttkbootstrap GUI

作者头像
geovindu
发布2026-06-18 21:43:13
发布2026-06-18 21:43:13
760
举报
代码语言:javascript
复制
"""
StudentUI.py
读文件类
date 2023-06-24
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11

"""

import datetime
import sys
import os
from tkinter import ttk
from tkinter import *
from tkinter.ttk import *
from ttkbootstrap import Style  # pip install ttkbootstrap
import random
import Model.StudentListInfo
import BLL.StudentListBLL

class StudentUi(object):

    global tree
    #stubll = BLL.StudentListBLL.StudentBll()

    def __del__(self):
        self.name="geovindu"

    def delete():
        global tree
        tree.delete(tree.selection())
        stubll = BLL.StudentListBLL.StudentBll()
        #cls.stubll.delSql()

    def main():
        """
        窗体绑定数据
        :return:
        """
        stubll = BLL.StudentListBLL.StudentBll()
        geovindu =stubll.selectSqlOrder("StudentNO asc") # list()

        style=Style(theme='darkly') #定义窗口样式
        window=style.master
        window.title("学生管理")
        # win = Tk()
        screenWidth = window.winfo_screenwidth()
        screenHeight = window.winfo_screenheight()
        width=100
        height=600
        x=int((screenWidth-width)/2)
        y=int((screenHeight-height)/2)
        window.geometry('{}x{}+{}+{}'.format(width,height,x,y))
        #Treeview 控件
        tree=ttk.Treeview(master=window,style='success.Treeview',height=25,show='headings')
        tree.pack()
        #定义列
        tree['columns']=("StudentId","StudentName","StudentNO","StudentBirthday","Age")
        #设置列属性,列不显示
        tree.column("StudentId",width=150,minwidth=100,anchor=S)
        tree.column("StudentName", width=150, minwidth=100, anchor=S)
        tree.column("StudentNO", width=150, minwidth=100, anchor=S)
        tree.column("StudentBirthday", width=150, minwidth=100, anchor=S)
        tree.column("Age", width=150, minwidth=100, anchor=S)
        #设置表头
        tree.heading("StudentId",text="序号")
        tree.heading("StudentName", text="姓名")
        tree.heading("StudentNO", text="学号")
        tree.heading("StudentBirthday", text="出生日期")
        tree.heading("Age", text="年龄")
        #treeView控件绑定数据
        i=1
        for Model.StudentListInfo.StudentList in geovindu:
            tree.insert("",i,text="2",values=(Model.StudentListInfo.StudentList.getStudentId(),Model.StudentListInfo.StudentList.getStudentName(),Model.StudentListInfo.StudentList.getStudentNO(),Model.StudentListInfo.StudentList.getStudentBirthday(),Model.StudentListInfo.StudentList.getAge()))
            i+=1
        #删除按钮
        ttk.Button(window,text="删除",style='success,TButton',command=StudentUi.delete).pack(side='left',padx=5,pady=10)
        window.mainloop()

输出:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2026-06-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档