人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

Python實戰(zhàn)項目之MySQL tkinter pyinstaller實現(xiàn)學(xué)生管理系統(tǒng)

發(fā)布日期:2021-12-21 22:39 | 文章來源:gibhub

終極版終于有時間給大家分享了?。。?。

我們先看一下效果圖。

1:登錄界面:

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

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

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('學(xué)生管理系統(tǒng)')
 
 Label(root, text="學(xué)號:").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é)號,姓名,性別,電話) 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('提示', '請輸入學(xué)號!')
  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 = ('學(xué)號', '姓名', '性別', '電話')
 treeview = ttk.Treeview(root, show='headings', columns=columns)
 treeview.column('學(xué)號', 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é)號', text='學(xué)號')
 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)
 
#鼠標(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('錯誤!','賬號或密碼錯誤!')
 
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

然后就成功啦!?。?!

最后總結(jié)一下:

這個gui界面其實還可以寫成學(xué)生登錄和老師登錄,再來一個注冊界面,都是用tk去實現(xiàn),然后老師和學(xué)生登陸后的功能不同,這個是一個想法,我沒有時間去寫了,有的小伙伴有時間可以去思考思考哦??!也歡迎和我討論,隨時歡迎?。。?/p>

最后點點贊吧,我快你沒動力分享了?。。?/p>

到此這篇關(guān)于Python實戰(zhàn)項目之MySQL tkinter pyinstaller實現(xiàn)學(xué)生管理系統(tǒng)的文章就介紹到這了,更多相關(guān)Python 學(xué)生管理系統(tǒng)內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部