首页 > 编程语言 >python: Treeview Control binding data using tkinter and ttkbootstrap GUI

python: Treeview Control binding data using tkinter and ttkbootstrap GUI

时间:2023-06-24 15:22:24浏览次数:37  
标签:Control tkinter python tree datetime StudentList import StudentListInfo Model

 

"""
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

class StudentUi(object):

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

    def delete():
        global tree
        tree.delete(tree.selection())

    def main():

        geovindu = list()
        geovindu.append(Model.StudentListInfo.StudentList(1, '王二', '002', datetime.datetime(2008, 2, 14, 0, 0)))
        geovindu.append(Model.StudentListInfo.StudentList(2, '涂年生', '003', datetime.datetime(2008, 2, 14, 0, 0)))
        geovindu.append(Model.StudentListInfo.StudentList(3, '涂聚文', '004', datetime.datetime(2008, 2, 14, 0, 0)))
        geovindu.append(Model.StudentListInfo.StudentList(4, '赵三', '001', datetime.datetime(2008, 2, 14, 0, 0)))
        geovindu.append(Model.StudentListInfo.StudentList(5, '李四', '005', datetime.datetime(2008, 2, 14, 0, 0)))

        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")
        #设置列属性,列不显示
        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.heading("StudentId",text="序号")
        tree.heading("StudentName", text="姓名")
        tree.heading("StudentNO", text="学号")
        tree.heading("StudentBirthday", 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()))
            i+=1
        #删除按钮
        ttk.Button(window,text="del",style='success,TButton',command=StudentUi.delete).pack(side='left',padx=5,pady=10)
        window.mainloop()

  

输出:

 

标签:Control,tkinter,python,tree,datetime,StudentList,import,StudentListInfo,Model
From: https://www.cnblogs.com/geovindu/p/17501147.html

相关文章

  • springboot 通过aop切面的方式打印controller 出入参数
    pom文件引入<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency>定义切面类AspectConfigimportcom.alibaba.fastjson.JSONObject;importlombok.extern.slf4j.......
  • 用python打开文件夹
    '''用python打开文件夹''''''https://blog.csdn.net/yqyangcyq/article/details/105677844'''os.system("explorer.exe%s"%str_dizh)#打开(可重复打开)目标文件夹os.startfile(str_dizh)#打开(并且屏幕上只存在一个/不会重复打开......
  • k8s驱逐篇(6)-kube-controller-manager驱逐-NodeLifecycleController源码分析
    概述k8sv1.16版本中NodeController已经分为了NodeIpamController与NodeLifecycleController,本文主要介绍NodeLifecycleController。NodeLifecycleController主要功能有:(1)定期检查node的心跳上报,某个node间隔一定时间都没有心跳上报时,更新node的readycondition值为false或unkno......
  • Python 3.11 无法使用opencv的解决方法
    尝试了各种办法,默认安装方法pipinstallopencv-python安装后,importcv2提示缺少dll文件。下载了opencv4.7,添加路径到环境变量PYTHONPATH,但是里面没有提供给python3.11的config.py只有给3.10的,还是不成功。所以,只好卸载了Python3.11,安装了Python3.10,直接用默认安装方法pipin......
  • python: object 专有方法
     """StudentScoreInfo.py学生成绩类date2023-06-16edit:GeovinDu,geovindu,涂聚文ide:PyCharm2023.1python11"""importdatetimeimportsysimportosclassStudentScore(object):"""学生成绩类"&q......
  • Python 求最大公约数
    题目要求求最大公约最简单快速的方式还是欧几里得算法原理:已知m、n两个不全为0的非负整数gcd(m,n)1:如果n=0,返回m作为结果,否则进入22:m对n取余,余数赋值给r3:将n赋值给m,r赋值给n,返回1参考实现defgcd(m,n):'''求最大公约数:paramm::paramn::ret......
  • python-docx处理Word
     用到的库?123456fromdocximportDocument(文档读写)fromdocx.sharedimportPt,Cm,Inches(字体大小,不一定全用到)fromdocx.oxml.nsimportqn(设置字体格式,分栏等用到)fromdocx.sharedimportRGBColor(设置字体颜色)fromdocx.enum.textimportWD_ALIG......
  • Python与TensorFlow:如何高效地构建和训练机器学习模型
    目录标题:《Python与TensorFlow:如何高效地构建和训练机器学习模型》一、引言随着人工智能的快速发展,机器学习作为其中的一个重要分支,受到了越来越多的关注和应用。而Python作为一门广泛应用于机器学习领域的编程语言,其与TensorFlow的结合也变得越来越重要。本文将介绍Python与......
  • Python字符串前缀u、r、b、f含义
    Python字符串前缀u、r、b、f含义1、字符串前加u例子:u"字符串中有中文"含义:前缀u表示该字符串是unicode编码,Python2中用,用在含有中文字符的字符串前,防止因为编码问题,导致中文出现乱码。另外一般要在文件开关标明编码方式采用utf8。Python3中,所有字符串默认都是unicode字符串......
  • 垃圾识别系统Python+TensorFlow+Django+卷积神经网络算法【完整代码系统】
    一、介绍垃圾识别系统,使用Python作为主要开发语言,基于深度学习TensorFlow框架,搭建卷积神经网络算法。并通过对5种垃圾数据集进行训练,最后得到一个识别精度较高的模型。并基于Django,开发网页端操作平台,实现用户上传一张垃圾图片识别其名称。二、效果展示三、演示视频+代码视......