Python实战项目之MySQL tkinter pyinstaller实现学生管理系统
作者:铁甲小宝同学 时间:2024-01-15 16:21:25
终极版终于有时间给大家分享了!!!。
我们先看一下效果图。
1:登录界面:
2:查询数据库所有的内容!
3:链接数据库:
4:最终的打包!
话不多说直接上代码!!!!
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
然后就成功啦!!!!
最后总结一下:
这个gui界面其实还可以写成学生登录和老师登录,再来一个注册界面,都是用tk去实现,然后老师和学生登陆后的功能不同,这个是一个想法,我没有时间去写了,有的小伙伴有时间可以去思考思考哦!!也欢迎和我讨论,随时欢迎!!!
最后点点赞吧,我快你没动力分享了!!!
来源:https://blog.csdn.net/m0_54355125/article/details/120070511
标签:Python,学生管理系统,实战项目
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js 数组随机字符串(广告不重复)
2024-04-18 09:37:20
详解php处理大并发大流量大存储
2023-07-21 13:11:02
![](https://img.aspxhome.com/file/2023/8/555181_0s.jpg)
浅谈php调用python文件
2024-05-05 09:31:42
![](https://img.aspxhome.com/file/2023/6/128266_0s.png)
Python实现将蓝底照片转化为白底照片功能完整实例
2021-06-08 21:40:55
![](https://img.aspxhome.com/file/2023/6/103686_0s.jpg)
Oracle to_char函数的使用方法
2024-01-19 01:47:37
MySQL执行状态的查看与分析
2024-01-23 18:48:56
![](https://img.aspxhome.com/file/2023/2/77312_0s.png)
Flask和Django框架中自定义模型类的表名、父类相关问题分析
2022-04-04 00:23:17
Python上下文管理器详细使用教程
2021-06-24 05:47:35
golang简单读写文件示例
2024-05-22 10:13:21
从基础开始建立一个JS代码库第1/2页
2024-04-16 10:40:59
Keras实现将两个模型连接到一起
2021-07-10 07:24:08
python装饰器原理源码示例分析
2022-03-25 18:31:04
![](https://img.aspxhome.com/file/2023/6/133856_0s.png)
ES6入门教程之Array.from()方法
2024-04-18 09:51:51
Python SQLAlchemy库的使用方法
2021-04-19 20:16:16
PHP简单预防sql注入的方法
2024-06-07 15:50:25
asp检测文件编码方法
2007-10-03 14:27:00
深底色页面设计指南[译]
2009-08-06 18:16:00
![](https://img.aspxhome.com/file/UploadPic/20098/6/darkdesign1-79s.jpg)
Python中的pandas表格模块、文件模块和数据库模块
2024-01-28 05:32:45
![](https://img.aspxhome.com/file/2023/6/99316_0s.png)
MySQL数据库导入导出数据之报错解答实例讲解
2024-01-24 14:56:49
![](https://img.aspxhome.com/file/2023/8/122878_0s.png)
微信小程序列表渲染功能之列表下拉刷新及上拉加载的实现方法分析
2024-05-11 09:34:44
![](https://img.aspxhome.com/file/2023/9/126159_0s.png)