目錄
一.知識點回顧 4
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