Python学生管理系统+MySQL+tkinter+pyinstaller(终章)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: Python学生管理系统+MySQL+tkinter+pyinstaller(终章)

我们先看一下效果图。


1:登录界面:

image.png



2:


查询数据库所有的内容!


image.png


3:


链接数据库:

image.png



4:最终的打包!

image.png



话不多说直接上代码!!!!


from tkinter import *
import pymysql
from tkinter.messagebox import *
from tkinter import ttk
def get_connect():
    conn = pymysql.connect(host='localhost', user="root", passwd='GAO147258369',database='stu')
    return conn
window = Tk()
window.geometry('500x300')
window.title('登录账号!')
def create():
    root =Toplevel()
    root.geometry('700x800')
    root.title('学生管理系统')
    Label(root, text="学号:").place(relx=0, rely=0.05, relwidth=0.1)
    Label(root, text="姓名:").place(relx=0.5, rely=0.05, relwidth=0.1)
    Label(root, text="性别:").place(relx=0, rely=0.1, relwidth=0.1)
    Label(root, text="电话:").place(relx=0.5, rely=0.1, relwidth=0.1)
    sid1 = StringVar()
    name1 = StringVar()
    sex1 = StringVar()
    phone = StringVar()
    Entry(root, textvariable=sid1).place(relx=0.1, rely=0.05, relwidth=0.37, height=25)
    Entry(root, textvariable=name1).place(relx=0.6, rely=0.05, relwidth=0.37, height=25)
    Entry(root, textvariable=sex1).place(relx=0.1, rely=0.1, relwidth=0.37, height=25)
    Entry(root, textvariable=phone).place(relx=0.6, rely=0.1, relwidth=0.37, height=25)
    def add():
        list1 = []
        list1.append(sid1.get())
        list1.append(name1.get())
        list1.append(sex1.get())
        list1.append(phone.get())
        # print(list1)
        connection = get_connect()
        cur = connection.cursor(cursor=pymysql.cursors.DictCursor)
        sql = 'insert into student(学号,姓名,性别,电话) values("%s","%s","%s", "%s")'
        sid = int(list1[0])
        name = list1[1]
        sex = list1[2]
        iphone = int(list1[3])
        try:
            cur.execute(sql % (sid, name, sex, iphone))
            connection.commit()
        except Exception as e:
            connection.rollback()
            raise e
        finally:
            connection.close()
        showinfo('提示', '添加成功!')
    def search():
        showinfo('提示', '请输入学号!')
        into = int(sid1.get())
        conn = pymysql.connect(host='localhost', user="root", passwd="", database='stu')
        cur = conn.cursor()
        sql = 'select * from student ;'
        cur.execute(sql)
        all = cur.fetchall()
        for i in range(len(all)):
            for j in all:
                if into == j[0]:
                    treeview.insert('', i, value=(j[0], j[1], j[2], j[3]))
                    break
            break
    def search_all():
        conn = pymysql.connect(host='localhost', user="root", passwd="", database='stu')
        cur = conn.cursor()
        sql = 'select * from student ;'
        cur.execute(sql)
        f = cur.fetchall()
        for i in range(len(f)):
            # for j in range(len(i)):
            treeview.insert('', i, value=(f[i][0], f[i][1], f[i][2], f[i][3]))
    Button(root, text="添加信息", command=add).place(relx=0.1, rely=0.2, width=100)
    Button(root, text="查询个人信息", command=search).place(relx=0.3, rely=0.2, width=100)
    Button(root, text="查询所有信息", command=search_all).place(relx=0.6, rely=0.2, width=100)
    Button(root, text="退出程序", command=root.quit).place(relx=0.8, rely=0.2, width=100)
    columns = ('学号', '姓名', '性别', '电话')
    treeview = ttk.Treeview(root, show='headings', columns=columns)
    treeview.column('学号', width=150, anchor='center')
    treeview.column('姓名', width=150, anchor='center')
    treeview.column('性别', width=150, anchor='center')
    treeview.column('电话', width=150, anchor='center')
    treeview.heading('学号', text='学号')
    treeview.heading('姓名', text='姓名')
    treeview.heading('性别', text='性别')
    treeview.heading('电话', text='电话')
    treeview.place(rely=0.3, relwidth=0.97)
Label(window,text = '账号:').place(relx =0, rely = 0.05,relwidth = 0.3)
Label(window,text = '密码:').place(relx = 0, rely = 0.15,relwidth =0.3)
#鼠标定位
zh = StringVar()
mm = StringVar()
#输入框
Entry(window,textvariable =zh, show = None).place(relx =0.3,rely = 0.05,relwidth = 0.3)
Entry(window,textvariable =mm,show ='*').place(relx = 0.3,rely = 0.15 ,relwidth = 0.3)
#欢迎大家找小宝交流哦QQ:2922035952
#登陆函数
def dl():
    if zh.get() == '20' and mm.get() == '' :
        # showinfo('提示!','登录成功!')
        # window.quit()
        return create()
    else:
        showerror('错误!','账号或密码错误!')
Button(window,text = '登录', command =dl).place(relx = 0.2 ,rely = 0.3, relwidth = 0.5)
window.mainloop()

还有最后一步——代码打包!!!


我们可以用库——pyinstaller


下载方法:打开cmd 输入 pip install pyinstaller


然后在Terminal里输入 pyinstaller -D -w xxxx.py


image.png


然后就成功啦!!!!







相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
20天前
|
人工智能 自然语言处理 程序员
体验通义灵码的AI程序员:用Python+Tkinter实现表单向config.ini写入与读取
本文介绍了如何利用通义灵码的AI程序员快速开发一个基于Python和Tkinter的表单应用程序,实现对config.ini文件的读写。通过简单的自然语言描述,通义灵码能自动生成代码框架、自动补全功能代码,并提供错误检测与修复建议,极大提高了开发效率。开发者只需安装必要库(如configparser)并配置VSCode插件TONGYI Lingma,即可轻松创建包含多个输入项和按钮的表单界面。运行程序后,用户可以编辑表单并保存数据到config.ini文件中,再次启动时数据会自动加载显示。这一过程展示了AI在编程中的高效性和灵活性,为开发者提供了全新的开发方式。
119 3
|
20天前
|
SQL 关系型数据库 MySQL
Python中使用MySQL模糊查询的方法
本文介绍了两种使用Python进行MySQL模糊查询的方法:一是使用`pymysql`库,二是使用`mysql-connector-python`库。通过这两种方法,可以连接MySQL数据库并执行模糊查询。具体步骤包括安装库、配置数据库连接参数、编写SQL查询语句以及处理查询结果。文中详细展示了代码示例,并提供了注意事项,如替换数据库连接信息、正确使用通配符和关闭数据库连接等。确保在实际应用中注意SQL注入风险,使用参数化查询以保障安全性。
|
6月前
|
SQL 关系型数据库 MySQL
MySQL操作利器——mysql-connector-python库详解
MySQL操作利器——mysql-connector-python库详解
1449 0
|
3月前
|
关系型数据库 MySQL 数据库
Python处理数据库:MySQL与SQLite详解 | python小知识
本文详细介绍了如何使用Python操作MySQL和SQLite数据库,包括安装必要的库、连接数据库、执行增删改查等基本操作,适合初学者快速上手。
448 15
|
4月前
|
数据可视化 开发者 Python
Python GUI开发:Tkinter与PyQt的实战应用与对比分析
【10月更文挑战第26天】本文介绍了Python中两种常用的GUI工具包——Tkinter和PyQt。Tkinter内置于Python标准库,适合初学者快速上手,提供基本的GUI组件和方法。PyQt基于Qt库,功能强大且灵活,适用于创建复杂的GUI应用程序。通过实战示例和对比分析,帮助开发者选择合适的工具包以满足项目需求。
298 7
|
5月前
|
关系型数据库 MySQL 数据库
Mysql学习笔记(四):Python与Mysql交互--实现增删改查
如何使用Python与MySQL数据库进行交互,实现增删改查等基本操作的教程。
104 1
|
6月前
|
前端开发 Python
python之【Tkinter模块】
python之【Tkinter模块】
90 5
|
6月前
|
关系型数据库 MySQL Python
mysql之python客户端封装类
mysql之python客户端封装类
|
5月前
|
XML JSON Ubuntu
Python实用记录(十五):PyQt/PySide6打包成exe,精简版(nuitka/pyinstaller/auto-py-to-exe)
本文介绍了使用Nuitka、PyInstaller和auto-py-to-exe三种工具将Python的PyQt/PySide6应用打包成exe文件的方法。提供了详细的安装步骤、打包命令和参数说明,适合新手学习和实践。
1003 0
|
6月前
|
SQL 关系型数据库 MySQL
30天拿下Python之使用MySQL
30天拿下Python之使用MySQL
71 0

热门文章

最新文章