Python實(shí)戰(zhàn)項(xiàng)目之MySQL tkinter pyinstaller實(shí)現(xiàn)學(xué)生管理系統(tǒng)
終極版終于有時(shí)間給大家分享了?。?!。

我們先看一下效果圖。
1:登錄界面:

2:查詢數(shù)據(jù)庫(kù)所有的內(nèi)容!

3:鏈接數(shù)據(jù)庫(kù):

4:最終的打包!

話不多說(shuō)直接上代碼?。。?!

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('登錄賬號(hào)!')
def create():
root =Toplevel()
root.geometry('700x800')
root.title('學(xué)生管理系統(tǒng)')
Label(root, text="學(xué)號(hào):").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(學(xué)號(hào),姓名,性別,電話) 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('提示', '請(qǐng)輸入學(xué)號(hào)!')
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="查詢個(gè)人信息", 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 = ('學(xué)號(hào)', '姓名', '性別', '電話')
treeview = ttk.Treeview(root, show='headings', columns=columns)
treeview.column('學(xué)號(hào)', width=150, anchor='center')
treeview.column('姓名', width=150, anchor='center')
treeview.column('性別', width=150, anchor='center')
treeview.column('電話', width=150, anchor='center')
treeview.heading('學(xué)號(hào)', text='學(xué)號(hào)')
treeview.heading('姓名', text='姓名')
treeview.heading('性別', text='性別')
treeview.heading('電話', text='電話')
treeview.place(rely=0.3, relwidth=0.97)
Label(window,text = '賬號(hào):').place(relx =0, rely = 0.05,relwidth = 0.3)
Label(window,text = '密碼:').place(relx = 0, rely = 0.15,relwidth =0.3)
#鼠標(biāo)定位
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
#登陸函數(shù)
def dl():
if zh.get() == '20' and mm.get() == '' :
# showinfo('提示!','登錄成功!')
# window.quit()
return create()
else:
showerror('錯(cuò)誤!','賬號(hào)或密碼錯(cuò)誤!')
Button(window,text = '登錄', command =dl).place(relx = 0.2 ,rely = 0.3, relwidth = 0.5)
window.mainloop()
還有最后一步——代碼打包!??!
我們可以用庫(kù)——pyinstaller
下載方法:打開(kāi)cmd 輸入 pip install pyinstaller
然后在Terminal里輸入 pyinstaller -D -w xxxx.py

然后就成功啦?。。?!
最后總結(jié)一下:
這個(gè)gui界面其實(shí)還可以寫成學(xué)生登錄和老師登錄,再來(lái)一個(gè)注冊(cè)界面,都是用tk去實(shí)現(xiàn),然后老師和學(xué)生登陸后的功能不同,這個(gè)是一個(gè)想法,我沒(méi)有時(shí)間去寫了,有的小伙伴有時(shí)間可以去思考思考哦??!也歡迎和我討論,隨時(shí)歡迎!??!
最后點(diǎn)點(diǎn)贊吧,我快你沒(méi)動(dòng)力分享了?。?!

到此這篇關(guān)于Python實(shí)戰(zhàn)項(xiàng)目之MySQL tkinter pyinstaller實(shí)現(xiàn)學(xué)生管理系統(tǒng)的文章就介紹到這了,更多相關(guān)Python 學(xué)生管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 十個(gè)Python練手的實(shí)戰(zhàn)項(xiàng)目,學(xué)會(huì)這些Python就基本沒(méi)問(wèn)題了(推薦)
- 分享7個(gè) Python 實(shí)戰(zhàn)項(xiàng)目練習(xí)
- Python實(shí)戰(zhàn)項(xiàng)目刮刮樂(lè)的實(shí)現(xiàn)詳解流程
- python實(shí)戰(zhàn)項(xiàng)目scrapy管道學(xué)習(xí)爬取在行高手?jǐn)?shù)據(jù)
- python游戲?qū)崙?zhàn)項(xiàng)目之童年經(jīng)典超級(jí)瑪麗
- python游戲的魅力之冒險(xiǎn)島實(shí)戰(zhàn)項(xiàng)目
- Python實(shí)戰(zhàn)項(xiàng)目用PyQt5制作漫畫臉GUI界面
- Python PyQt5實(shí)戰(zhàn)項(xiàng)目之網(wǎng)速監(jiān)控器的實(shí)現(xiàn)
- python爬蟲實(shí)戰(zhàn)項(xiàng)目之爬取pixiv圖片
- 使用python來(lái)玩一次股票代碼詳解
相關(guān)文章
Python常問(wèn)的100個(gè)面試問(wèn)題匯總(上篇)
這篇文章主要介紹了Python常問(wèn)的100個(gè)面試問(wèn)題匯總(上篇),文章內(nèi)容詳細(xì),簡(jiǎn)單易懂,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2023-01-01
Django-migrate報(bào)錯(cuò)問(wèn)題解決方案
這篇文章主要介紹了Django-migrate報(bào)錯(cuò)問(wèn)題解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
python實(shí)現(xiàn)在列表中查找某個(gè)元素的下標(biāo)示例
這篇文章主要介紹了python實(shí)現(xiàn)在列表中查找某個(gè)元素的下標(biāo)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
使用python編寫android截屏腳本雙擊運(yùn)行即可
使用python編寫一個(gè)截屏的腳本,雙擊運(yùn)行腳本就OK,截屏成功后會(huì)將截屏文件已當(dāng)前時(shí)間命名,并保存在存放腳本的當(dāng)前路徑的screenshot文件夾下2014-07-07

