基于tkinter的学生信息管理系统之登录界面和主界面菜单设计

目录

一、tkinter的介绍

二、登陆界面的设计

1、登陆界面完整代码

2、部分代码讲解

3、登录的数据模型设计

 4、效果展示

三、学生主界面菜单设计

 1、学生主界面菜单设计完整代码

2、 部分代码讲解

 3、效果展示

四、数据库的模型设计


 

欢迎大家进来学习和支持!!!

今天主要带来的是使用tkinter来制作一期学生信息管理系统

一、tkinter的介绍

tkinter就是python语言里面用来制作一个GUI界面的一个包,这里长话短说,不做过多的言语上的阐述,想了解更多可以点击下面的链接

tkinter官网教程

二、登陆界面的设计

我们开始编写代码的之前,我们的自己先了解一些关于tkinter中的一些组件的使用和方法 

1、登陆界面完整代码

"""
Ryan 2024.7.28
登陆页面的制作
"""
import tkinter as tk
from tkinter import messagebox
from db import db
from mainPage import mainPageclass loginFarme(object):def __init__(self, window):self.window = windowself.window.geometry("300x180")self.window.title("登录界面")# 创建变量对象self.username = tk.StringVar()self.password = tk.StringVar()# 用于后面进行页面换页用的self.page = tk.Frame(window)self.page.pack()# 再page里面布局tk.Label(self.page).grid(row=0, column=0)tk.Label(self.page, text="账户:", font=28).grid(row=1, column=1)# textvariable:文本变量tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)tk.Label(self.page, text="密码:", font=28).grid(row=3, column=1, pady=10)tk.Entry(self.page, textvariable=self.password).grid(row=3, column=2)tk.Button(self.page, text="登录", font=28, command=self.login).grid(row=5, column=1, pady=10)tk.Button(self.page, text="退出", font=28, command=self.page.quit).grid(row=5, column=2)# 登录功能def login(self):name = self.username.get()pwd = self.password.get()flag, message = db.checkLogin(name, pwd)if flag:# 销毁第一页self.page.destroy()# 重新给页面添加内容mainPage(self.window)else:messagebox.showwarning(title="警告", message=message)if __name__ == '__main__':window = tk.Tk()loginFarme(window)window.mainloop()

2、部分代码讲解

对于loginFarme类的讲解:

        这个属于类的初始化函数部分,给登录界面创建界面组件用 

    def __init__(self, window):self.window = windowself.window.geometry("300x180")self.window.title("登录界面")# 创建变量对象self.username = tk.StringVar()self.password = tk.StringVar()# 用于后面进行页面换页用的self.page = tk.Frame(window)self.page.pack()# 再page里面布局tk.Label(self.page).grid(row=0, column=0)tk.Label(self.page, text="账户:", font=28).grid(row=1, column=1)# textvariable:文本变量tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)tk.Label(self.page, text="密码:", font=28).grid(row=3, column=1, pady=10)tk.Entry(self.page, textvariable=self.password).grid(row=3, column=2)tk.Button(self.page, text="登录", font=28, command=self.login).grid(row=5, column=1, pady=10)tk.Button(self.page, text="退出", font=28, command=self.page.quit).grid(row=5, column=2)

         这一部分是为了实现登陆的功能和警告信息,这里面调用了db这个类对象checkLogin方法,是为了检查账户密码的正确性,这个类对象会在后面定义,这里的mainPage方法是调用了mainPage.py文件里的方法,为了登录成功后进入到学生管理系统主界面

 # 登录功能def login(self):name = self.username.get()pwd = self.password.get()flag, message = db.checkLogin(name, pwd)if flag:# 销毁第一页self.page.destroy()# 重新给页面添加内容mainPage(self.window)else:messagebox.showwarning(title="警告", message=message)

         这个代码块想必大家都很熟悉,这个代码块主要是为了检查该程序是否能够在这个文件里运行,这里的tk.Tk()和mainloop()方法是打开窗口界面和循环显示窗口界面的功能

if __name__ == '__main__':window = tk.Tk()loginFarme(window)window.mainloop()

3、登录的数据模型设计

        这里是主要封装了一个对于登录信息的检查,这里没有用到数据库,而是自己创建了一个json的数据模型来代替,这个就是上面所说到的checkLogin()方法的定义代码 

"""
Ryan 2024.7.28
建立登录的数据模型
"""
import jsonclass mySqlDatabases(object):def __init__(self):with open('student.json', mode='r', encoding='utf-8') as f:text = f.read()self.students = json.loads(text)f.close()def checkLogin(self, username, password):for student in self.students:if username == student['username']:if password == student['password']:return True, '登陆成功'else:return False, '登陆失败,密码不存在'return False, '登陆失败,用户名不存在'# 实例化类对象
db = mySqlDatabases()
if __name__ == '__main__':print(db.checkLogin('admin', '123456'))

 4、效果展示

三、学生主界面菜单设计

接下来我们设计好登录界面后,就是进入到学生的主界面设计 

 1、学生主界面菜单设计完整代码

"""
Ryan 2024.7.28
学生页面的制作
"""
import tkinter as tkclass mainPage(object):# window:tk.Tk只作为一个提示是TK对象,写完这个就可以显示方法提示def __init__(self, window: tk.Tk):self.window = windowself.window.geometry('600x400')self.window.title('学生管理系统 V0.0.1')self.createPage()def createMenu(self):self.aboutFrame = tk.Frame(self.window)tk.Label(self.aboutFrame, text='关于作品:本作品是tkinter制作的').pack()tk.Label(self.aboutFrame, text='关于作者:Ryan').pack()tk.Label(self.aboutFrame, text='版权所有:Ryan').pack()self.changeFrame = tk.Frame(self.window)tk.Label(self.changeFrame, text='修改页面').pack()self.deleteFrame = tk.Frame(self.window)tk.Label(self.deleteFrame, text='删除页面').pack()self.searchFrame = tk.Frame(self.window)tk.Label(self.searchFrame, text='搜索页面').pack()self.insertFrame = tk.Frame(self.window)tk.Label(self.insertFrame, text='录入页面').pack()def createPage(self):self.createMenu()menuBar = tk.Menu(self.window)menuBar.add_command(label='录入', command=self.showInsert)menuBar.add_command(label='查询', command=self.showSearch)menuBar.add_command(label='删除', command=self.showDelete)menuBar.add_command(label='修改', command=self.showChange)menuBar.add_command(label='关于', command=self.showAbout)# 将menuBar添加窗口中self.window['menu'] = menuBardef showAbout(self):self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.aboutFrame.pack()def showChange(self):self.aboutFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.changeFrame.pack()def showDelete(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.deleteFrame.pack()def showSearch(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.insertFrame.pack_forget()self.searchFrame.pack()def showInsert(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack()if __name__ == '__main__':window = tk.Tk()mainPage(window)window.mainloop()

2、 部分代码讲解

 以下主要是针对mainPage类的讲解:

        这里面的createPage函数是添加界面中的菜单按钮,command是当按钮被点击的时候会触发的事件

    def createPage(self):self.createMenu()menuBar = tk.Menu(self.window)menuBar.add_command(label='录入', command=self.showInsert)menuBar.add_command(label='查询', command=self.showSearch)menuBar.add_command(label='删除', command=self.showDelete)menuBar.add_command(label='修改', command=self.showChange)menuBar.add_command(label='关于', command=self.showAbout)# 将menuBar添加窗口中self.window['menu'] = menuBar

        以下是菜单被点击的时候所触发的函数方法 ,这里面的pack_forget方法是为了清除界面添加的内容,防止内容会一直保留到界面当中

    def showAbout(self):self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.aboutFrame.pack()def showChange(self):self.aboutFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.changeFrame.pack()def showDelete(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.deleteFrame.pack()def showSearch(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.insertFrame.pack_forget()self.searchFrame.pack()def showInsert(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack()

 3、效果展示

当你点击下面不同菜单的时候,会进入到不同的页面 

 

四、数据库的模型设计

采用json格式去设计数据模块,后期会用上数据库的连结 

[{"username": "admin","password": "123456"},{"username": "Ryan","password": "123456"}
]

 今天的分享就是这样了,下次带来关于学生信息管理系统的进一步页面设计。

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/51431.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

灯具外贸公司用什么企业邮箱好

灯具外贸公司面对海外市场的推广、产品销售、客户沟通、市场信息收集等多重需求,选择一个合适的企业邮箱显得尤为重要。本文将介绍灯具外贸公司为什么应选择Zoho Mail企业邮箱,并详细探讨其优势和功能。 一、公司背景 广东省深圳市光明新区&#xff0c…

持久化存储:Mojo模型中模型保存与加载的艺术

持久化存储:Mojo模型中模型保存与加载的艺术 在机器学习项目中,模型的持久化存储是一个关键环节,它允许我们将训练好的模型保存下来,并在需要时重新加载使用。Mojo模型,作为一个虚构的高级机器学习框架,支…

Redis 安装和数据类型

Redis 安装和数据类型 一、Redis 1、Redis概念 redis 缓存中间件:缓存数据库 nginx web服务 php 转发动态请求 tomcat web页面,也可以转发动态请求 springboot 自带tomcat 数据库不支持高并发,一旦访问量激增,数据库很快就…

vTESTstudio中如何添加DLL文件?

文章目录 一、CANoe添加DLL二、vTESTstudio中添加DLL1.手动添加2.代码添加 一、CANoe添加DLL 在CANoe中添加DLL的路径如下图,在Simulation Setup中选择需要添加的节点,右键选择Configuration进行添加DLL。 二、vTESTstudio中添加DLL 1.手动添加 在打…

java中 VO DTO BO PO DAO

VO、DTO、BO、PO、DO、POJO 数据模型的理解和实际使用_vo dto bo-CSDN博客 深入理解Java Web开发中的PO、VO、DTO、DAO和BO概念_java dto dao-CSDN博客

【计算机网络】WireShark和简单http抓包实验

一:实验目的 1:熟悉WireShark的安装流程和界面操作流程。 2:学会简单http的抓取和过滤,并分析导出结果。 二:实验仪器设备及软件 硬件: Windows 2019操作系统的计算机等。 软件:WireShark、…

【算法/训练】:动态规划(线性DP)

一、路径类 1. 字母收集 思路: 1、预处理 对输入的字符矩阵我们按照要求将其转换为数字分数,由于只能往下和往右走,因此走到(i,j)的位置要就是从(i - 1, j)往下走&#…

vector清空

https://www.zhihu.com/question/592055868/answer/2967078686

java使用hutool工具检查远程端口是否开启

使用java校验ip地址或域名的端口是否开启 1.导入hutool工具的maven依赖 <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.16</version></dependency>2.复制一下代码案例直接运行 …

前端面试基础题(微信公众号:前端面试成长之路)

BFC、IFC、GFC、FFC CSS2.1中只有BFC和IFC, CSS3中才有GFC和FFC。 到底什么是BFC、IFC、GFC和FFC Whats FC&#xff1f; 一定不是KFC&#xff0c;FC的全称是&#xff1a;Formatting Contexts&#xff0c;是W3C CSS2.1规范中的一个概念。它是页面中的一块渲染区域&#xff0c;并…

量度卓越:Mojo模型中自定义评估与模型比较的艺术

量度卓越&#xff1a;Mojo模型中自定义评估与模型比较的艺术 在机器学习项目中&#xff0c;模型评估是衡量算法性能的关键步骤。Mojo模型&#xff0c;作为一个先进的机器学习框架&#xff0c;提供了丰富的工具来支持模型评估和比较。本文将深入探讨如何在Mojo模型中实现自定义…

openj9-17.0.2_8-jre-alpine 和 openjdk:17-alpine 的区别是什么?

openj9-17.0.2_8-jre-alpine 和 openjdk:17-alpine 都是用于运行 Java 应用程序的 Docker 镜像&#xff0c;但它们之间有一些关键的区别&#xff1a; JVM Implementation: openj9-17.0.2_8-jre-alpine 使用的是 Eclipse OpenJ9&#xff0c;这是一种高效、低内存消耗的 JVM 实现…

go-sql-driver/mysql 查询 latin1 中文字符集

select name from table; table是 latin1 编码&#xff0c; 返回后查询结果后&#xff0c;即使将 name 转为 utf-8&#xff0c;日志输出中文仍然乱码。 // 配置数据库连接字符串&#xff0c;确保指定charsetlatin1dsn : "user:passwordtcp(127.0.0.1:3306)/dbname?chars…

免费【2024】springboot 宠物领养救助平台的开发与设计

博主介绍&#xff1a;✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌ 技术范围&#xff1a;SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化…

每日一练,java07

目录 题目1.请问运行主要的程序会打印出的是什么&#xff08;&#xff09;2.下面论述正确的是&#xff08;&#xff09;&#xff1f;3.下面哪些Java中的流对象是字节流?4.关于以下代码的说明&#xff0c;正确的是&#xff08; &#xff09;5.若需要定义一个类&#xff0c;下列…

普元EOS学习笔记-EOS项目HTTP访问安全和权限控制

前言 对于企业应用系统&#xff0c;出于安全和权限控制的目的&#xff0c;需要对http请求做若干控制。 比如文件上传的时候要控制不允许上传的文件后缀。 又比如控制应用程序中的哪些资源不允许被访问。 EOS项目通过 xml配置文件来实现这一需求。 Http访问管理模块 在EOS项…

Keepalived、MyCAT 和 MHA这三者之间的区别

最近公司要做主备数据库备份和自动切换&#xff0c;先简单的了解了一下这三者的区别。 要做一个主库宕机之后自动切换备库的功能&#xff0c;但是上网搜索了一下发现有三个中间件都可以解决这个问题。 所以就来说一下这三个的业务场景和区别&#xff0c;以及哪一个更加轻量级 …

Spring JPA不生效

今天排查老半天发现数据源被排除装配了&#xff0c;把这个去掉就行了 SpringBootApplication(exclude DataSourceAutoConfiguration.class)

vue项目的路由如何传参,应用场景

路由传参方法一&#xff1a; params 1. 在路由的配置中 path: url:proid 先在配置中添加 2. 跳转页面的时候携带拼接参数 router.push(url proid) 3. 在进入的页面通过 useRoute 进行接收 4. const route useRoute() 5. console.log(route.params.proid); 路由传参方法二…

DBoW3相关优化脉络

1 DBow3 GitHub - rmsalinas/DBow3: Improved version of DBow2 2 优化后得到fbow GitHub - rmsalinas/fbow: FBOW (Fast Bag of Words) is an extremmely optimized version of the DBow2/DBow3 libraries. 其中fbow是ucoslam的一部分&#xff1b; ucoslam GitHub - la…