程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Student Information Management System Based on Python

編輯:Python

目錄
一.知識點回顧 4

  1. python基礎 4
    2.tkinter庫 4
  2. MySQL數據庫 4
    一. 前期准備 5
  3. 工具使用 5
    2.數據庫創建(students庫) 5
    ① 賬戶信息表(verify) 5
    ② 學生信息表(student) 5
    ③ 學生成績表(score) 5
    二. 設計基本思路 6
  4. 登錄 6
  5. 注冊 6
  6. 學生端 6
  7. 教師端 6
    三. 設計流程 7
  8. 登錄和注冊頁面 8
  9. 學生端頁面 8
  10. 教師端頁面 8
  11. Student basic information modification page 9
  12. Student grade entry interface 9
  13. Student Information Sheet and Student Score Sheet 10
  14. 密碼修改頁面 11
    六.總結 11
  15. 心得體會 11
  16. PythonAdvantages for big data majors 11
    七.核心代碼 12
  17. 學生信息修改 12
  18. 學生成績錄入 14
  19. 學生信息刪除 17
  20. 注冊 17
    一.知識點回顧
    1.python基礎
    2.tkinter庫
    Python自帶了tkinter 模塊,實質上是一種流行的面向對象的GUI工具包 TK 的Python編程接口,提供了快速便利地創建GUI應用程序的方法.其圖像化編程的基本步驟通常包括:導入 tkinter 模塊,創建 GUI 根窗體,添加人機交互控件並編寫相應的函數.在主事件循環中等待用戶觸發事件響應.
    Tkinter的優勢:相比Python的其他GUI庫更加簡單,跨平台,Python的標准庫,不需要安裝.
    2.MySQL數據庫
    Unified management of data,It is convenient for data management and program calling,MySQLDatabase as an open source database,Has a small software size,安裝使用簡單,並且易於維護,Features of low installation and maintenance costs.
    數據庫的優點:
    1.持久化數據到本地
    2.可以實現結構化查詢,方便
    數據庫相關概念:
    1、DB:數據庫,保存一組有組織的數據的容器
    2、DBMS:數據庫管理系統,又稱為數據庫軟件(產品),用於管理DB中的數據
    3、SQL:結構化查詢語言,用於和DBMS通信的
    數據庫存儲數據的特點:
    1、將數據放到表中,表再放到庫中
    2、一個數據庫中可以有多個表,每個表都有一個的名字,用來標識自己.表名具有唯一性.
    3、表具有一些特性,這些特性定義了數據在表中如何存儲,類似java中 “類”的設計.
    4、表由列組成,我們也稱為字段.所有表都是由一個或多個列組成的,每一列類似java 中的“屬性”
    5、表中的數據是按行存儲的,每一行類似於java中的“對象”
    一.前期准備
    1.工具使用
    Pycharm,vscode
    數據庫:MySQL,SQLyog
    本文轉載自:http://www.biyezuopin.vip/onews.asp?id=16539
import tkinter as tk
from tkinter import ttk
import tkinter.messagebox as mb
import sqlite3
# 連接數據庫
cn = sqlite3.connect('student.db')
cur = cn.cursor()
# 登錄信息驗證
def verify():
s1 = c1.get()
s2 = e1.get()
s3 = e2.get()
if s2 == '' or s3 == '':
y1 = mb.showinfo('登錄', 'Please enter account and password')
print(y1)
else:
cur.execute('select * from verify where mold=? and name=? and password=?', (s1, s2, s3,))
lg = cur.fetchone()
if lg:
y2 = mb.showinfo('登錄', '登錄成功')
print(y2)
if s1 == '學生':
rt.destroy()
student(s2)
elif s1 == '教師':
rt.destroy()
teacher(s2)
else:
y3 = mb.showinfo('登錄', '用戶名或密碼錯誤,請檢查!')
print(y3)
return 0
# 注冊頁面
def login():
def close():
rt1.destroy()
def into():
s7 = var7.get()
s6 = var6.get()
s4 = c2.get()
s5 = var5.get()
if s4 == '' or s5 == '' or s6 == '' or s7 == '':
y4 = mb.showinfo('注冊', 'Please enter account and password')
print(y4)
else:
if s6 == s7:
if s5.isdigit():
if 0 <= int(s5) < 100000:
cur.execute('select * from verify where name=?', (s5,))
lg = cur.fetchone()
if lg:
y6 = mb.showinfo('注冊', '用戶名已存在')
print(y6)
else:
if s4 == '教師':
cur.execute('insert into verify values(?,?,?)', (s5, s6, s4,))
cn.commit()
y8 = mb.showinfo('注冊', '注冊成功')
print(y8)
rt1.destroy()
elif s4 == '學生':
cur.execute('insert into verify values(?,?,?)', (s5, s6, s4,))
cur.execute('insert into students values(?,0 ,0 ,0 ,0 ,0 , 0)', (s5,))
cur.execute('insert into score values(?,0,0,0,0,0,0)', (s5,))
cn.commit()
print(s4 + s5 + s6)
y8 = mb.showinfo('注冊', '注冊成功')
print(y8)
rt1.destroy()
else:
y7 = mb.showinfo('注冊', '賬號格式錯誤')
print(y7)
else:
y8 = mb.showinfo('注冊', '賬號格式錯誤')
print(y8)
else:
y5 = mb.showinfo('注冊', '兩次輸入密碼不同')
print(y5)
rt1 = tk.Toplevel()
rt1.title("賬號注冊")
rt1.geometry('400x400')
rt1.update()
curx1 = rt1.winfo_width()
cury1 = rt1.winfo_height()
scnx1 = rt1.winfo_screenwidth()
scny1 = rt1.winfo_screenheight()
tm1 = '%dx%d+%d+%d' % (curx1, cury1, (scnx1 - curx1) / 2 + 400, (scny1 - cury1) / 2)
rt1.geometry(tm1)
rt1.resizable(False, False)
var4 = tk.StringVar()
c2 = ttk.Combobox(rt1, textvariable=var4, font=("宋體", 20), state='readonly')
c2['values'] = ("學生", "教師")
c2["state"] = "readonly"
c2.set("學生")
c2.current(0)
c2.place(x=40, y=40)
b14 = tk.Label(rt1, text="賬號", font=("宋體", 20))
b14.place(x=40, y=100)
var5 = tk.StringVar()
e13 = tk.Entry(rt1, textvariable=var5, width=15, font=("宋體", 20))
e13.place(x=120, y=100)
b15 = tk.Label(rt1, text="密碼", font=("宋體", 20))
b15.place(x=40, y=160)
var6 = tk.StringVar()
e14 = tk.Entry(rt1, textvariable=var6, width=15, font=("宋體", 20), show='*')
e14.place(x=120, y=160)
e14.focus_set()
b6 = tk.Label(rt1, text="確認密碼", font=("宋體", 20))
b6.place(x=20, y=220)
var7 = tk.StringVar()
e6 = tk.Entry(rt1, textvariable=var7, width=15, font=("宋體", 20), show='*')
e6.place(x=130, y=220)
e6.focus_set()
bu3 = tk.Button(rt1, text="注冊", width=7, height=1, font=("華文行楷", 20), command=lambda: into())
bu3.place(x=60, y=300)
bu4 = tk.Button(rt1, text="返回", width=7, height=1, font=("華文行楷", 20), command=lambda: close())
bu4.place(x=200, y=300)
b5 = tk.Label(rt1, text="注意:The account number is the student number or teacher number,由1~5位阿拉伯數字組成", font=("宋體", 10), width=45, height=2)
b5.place(x=40, y=360)
rt1.mainloop()
return 0
# 修改密碼
def xiugaimima(s):
def into(s):
s1 = e1.get()
s2 = e2.get()
s3 = e3.get()
print(s)
cur.execute('select * from verify where name=?',(s,))
tm4 = cur.fetchone()
print(tm4[1])
if s1 == '' or s2 == '' or s3 == '':
y1 = mb.showinfo('密碼修改', '請輸入密碼')
print(y1)
else:
if s2 == s3:
if s1 == tm4[1]:
cur.execute('update verify set password=? where name=?', (s2, s,))
cn.commit()
lg = cur.fetchone()
y3 = mb.showinfo('密碼修改', '密碼修改成功')
print(y3)
rt7.destroy()
return 1
else:
y3 = mb.showinfo('密碼修改', '原密碼錯誤')
print(y3)
else:
y2 = mb.showinfo('密碼修改', '兩次輸入密碼不同')
print(y2)
def close():
rt7.destroy()
rt7 = tk.Tk()
rt7.title("密碼修改")
rt7.geometry('400x300')
rt7.update()
curx = rt7.winfo_width()
cury = rt7.winfo_height()
scnx = rt7.winfo_screenwidth()
scny = rt7.winfo_screenheight()
tm3 = '%dx%d+%d+%d' % (curx, cury, (scnx - curx) / 2, (scny - cury) / 2)
rt7.geometry(tm3)
rt7.resizable(False, False)
b1 = tk.Label(rt7, text="舊密碼:", font=("宋體", 20))
b1.place(x=40, y=40)
var1 = tk.StringVar()
e1 = tk.Entry(rt7, textvariable=var1, width=15, font=("宋體", 20), show='*')
e1.place(x=160, y=40)
b2 = tk.Label(rt7, text="新密碼:", font=("宋體", 20))
b2.place(x=40, y=100)
var2 = tk.StringVar()
e2 = tk.Entry(rt7, textvariable=var2, width=15, font=("宋體", 20), show='*')
e2.place(x=160, y=100)
b3 = tk.Label(rt7, text="確認密碼:", font=("宋體", 20))
b3.place(x=40, y=160)
var3 = tk.StringVar()
e3 = tk.Entry(rt7, textvariable=var3, width=15, font=("宋體", 20), show='*')
e3.place(x=160, y=160)
bu3 = tk.Button(rt7, text="確定", width=7, height=1, font=("華文行楷", 20), command=lambda: into(s))
bu3.place(x=60, y=230)
bu4 = tk.Button(rt7, text="取消", width=7, height=1, font=("華文行楷", 20), command=lambda: close())
bu4.place(x=200, y=230)
rt7.mainloop()
# 學生個人信息修改
def xinxixiugei(s):
def close():
rt6.destroy()
def tijiao():
s1 = e1.get()
s2 = c2.get()
s3 = c3.get()
s4 = e4.get()
s5 = e5.get()
s6 = c6.get()
if s1 == '' or s2 == '' or s3 == '' or s4== '' or s5 == '' or s6 == '':
y2 = mb.showinfo('信息修改', '信息修改成功')
print(y2)
else:
if s5.isdigit():
if 9999999999 < int(s5) < 100000000000:
cur.execute('update students set name=?, sex=?, age=?, grade=?, phone=?, college=? where id=?', (s1,s2,s3,s4,s5,s6,s,))
cur.execute('update score set name=?, grade=? where id=?',(s1, s4, s,))
cn.commit()
y1 = mb.showinfo('信息修改', '信息修改成功')
print(y1)
rt6.destroy()
else:
y3 = mb.showinfo('信息修改', 'The number of digits in the phone number is wrong')
print(y3)
else:
y3 = mb.showinfo('信息修改', '電話號碼格式錯誤')
print(y3)
rt6 = tk.Tk()
rt6.title("學生個人信息修改")
rt6.geometry('500x400')
rt6.update()
curx = rt6.winfo_width()
cury = rt6.winfo_height()
scnx = rt6.winfo_screenwidth()
scny = rt6.winfo_screenheight()
tm6 = '%dx%d+%d+%d' % (curx, cury, (scnx - curx) / 2, (scny - cury) / 2)
rt6.geometry(tm6)
rt6.resizable(False, False)
cur.execute('select * from students where id=?', (s,))
tm1 = cur.fetchone()
b1 = tk.Label(rt6, text="姓名:", font=("宋體", 20))
b1.place(x=40, y=40)
var1 = tk.StringVar()
e1 = tk.Entry(rt6, textvariable=var1, width=10, font=("宋體", 20))
e1.place(x=120, y=40)
e1.insert(0,tm1[1])
b2 = tk.Label(rt6, text="性別:", font=("宋體", 20))
b2.place(x=40, y=100)
var2 = tk.StringVar()
c2 = ttk.Combobox(rt6, textvariable=var2, width=9, font=("宋體", 20))
c2['values'] = ("男", "女")
c2["state"] = "readonly"
c2.current(0)
c2.set(tm1[2])
c2.place(x=120, y=100)
b3 = tk.Label(rt6, text="年齡:", font=("宋體", 20))
b3.place(x=40, y=160)
var3 = tk.StringVar()
c3 = ttk.Combobox(rt6, textvariable=var3, width=9, font=("宋體", 20))
c3['values'] = ("17", "18", "19", "20", '21', '22', '23', '24', '25')
c3["state"] = "readonly"
c3.current(2)
c3.set(tm1[3])
c3.place(x=120, y=160)
b4 = tk.Label(rt6, text="班級:", font=("宋體", 20))
b4.place(x=40, y=220)
var4 = tk.StringVar()
e4 = tk.Entry(rt6, textvariable=var4, width=10, font=("宋體", 20))
e4.insert(0,tm1[4])
e4.place(x=120, y=220)
b5 = tk.Label(rt6, text="電話:", font=("宋體", 20))
b5.place(x=40, y=280)
var5 = tk.StringVar()
e5 = tk.Entry(rt6, textvariable=var5, width=10, font=("宋體", 20))
e5.insert(0, tm1[5])
e5.place(x=120, y=280)
b6 = tk.Label(rt6, text="學院:", font=("宋體", 20))
b6.place(x=40, y=340)
var6 = tk.StringVar()
c6 = ttk.Combobox(rt6, textvariable=var6, width=9, font=("宋體", 20))
c6['values'] = ("電子與信息工程學院", "機械工程學院", '數學學院')
c6["state"] = "readonly"
c6.current(0)
c6.set(tm1[6])
c6.place(x=120, y=340)
b7 = tk.Label(rt6, text='學號:'+tm1[0],font=('華文行楷',20))
b7.place(x=300,y=40)
bu7 = tk.Button(rt6, text="提交信息", width=16, height=1, font=("宋體", 15), command=lambda: tijiao())
bu7.place(x=300, y=100)
bu8 = tk.Button(rt6, text="退出", width=10, height=1, font=("宋體", 15), command=lambda: close())
bu8.place(x=300, y=200)
rt6.mainloop()
return 0















  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved