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:最終的打包!

話不多說直接上代碼!!?。?/p>

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
下載方法:打開cmd 輸入 pip install pyinstaller
然后在Terminal里輸入 pyinstaller -D -w xxxx.py

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

到此這篇關(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就基本沒問題了(推薦)
- 分享7個(gè) Python 實(shí)戰(zhàn)項(xiàng)目練習(xí)
- Python實(shí)戰(zhàn)項(xiàng)目刮刮樂的實(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來玩一次股票代碼詳解
相關(guān)文章
Python判斷某個(gè)用戶對(duì)某個(gè)文件的權(quán)限
這篇文章主要為大家詳細(xì)介紹了Python如何判斷某個(gè)用戶對(duì)某個(gè)文件的權(quán)限,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
Python數(shù)據(jù)結(jié)構(gòu)樹與算法分析
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)樹與算法分析,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-07-07
Python實(shí)現(xiàn)的ftp服務(wù)器功能詳解【附源碼下載】
這篇文章主要介紹了Python實(shí)現(xiàn)的ftp服務(wù)器功能,結(jié)合實(shí)例形式分析了Python構(gòu)建ftp服務(wù)器功能的相關(guān)設(shè)置、實(shí)現(xiàn)技巧與操作注意事項(xiàng),并附帶源碼供讀者下載參考,需要的朋友可以參考下2019-06-06
selenium+python 對(duì)輸入框的輸入處理方法
今天小編就為大家分享一篇selenium+python 對(duì)輸入框的輸入處理方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10
python實(shí)現(xiàn)密碼驗(yàn)證合格程序的思路詳解
這篇文章主要介紹了python實(shí)現(xiàn)密碼驗(yàn)證合格程序的思路詳解,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06

