赞
踩
目录
一.知识点回顾 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('登录', '请输入账户与密码') 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('注册', '请输入账户与密码') 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="注意:账号为学号或教师编号,由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('信息修改', '电话号码位数错误') 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。