学生信息管理系统(python)

最好将以下三个文件放在pycharm同一个目录下

登录窗口代码

 将文件名设置为“登录窗口”

from tkinter import *       # Tkinter是Python的标准GUI库,易于学习和使用。它提供了创建窗口、按钮、文本框等常见GUI组件的功能。
import os
import re   # 正则
import webbrowser
from tkinter.messagebox import *


#注册窗口
def Register():
    app.destroy()
    os.system("python 注册窗口.py")


#登录信息检测
def Login():
    cookie = False
    user_test = False
    passwd_test = False
    user_text = user.get()
    user_label = Label(app, text='用户名不能少于4个字节,且不多于12个字节', bg='#BABABA', fg='#FF0000')
    passwd_text = passwd.get()
    passwd_label = Label(app, text='密码不能少于6个字节,且不多于22个字节', bg='#BABABA', fg='#FF0000')
    # 正则
    r = r'^[a-zA-Z0-9]+$'

    # 过滤输入规则
        # 用户名规则
    if 4 <= len(user_text) <= 12:
        if re.match(r, user_text):
            user_test = True
        else:
            user_label = Label(app, text='不符合规则,只能输入字母和数字', bg='#BABABA', fg='#FF0000')
            user_label.place(x=100, y=75)
            user_label.after(3000, user_label.destroy)
    else:
        user_label.place(x=100, y=75)
        user_label.after(3000, user_label.destroy)
        # 密码规则
    if 6 <= len(passwd_text) <= 22:
        passwd_label.forget()
        if re.match(r, passwd_text):
            passwd_test = True
        else:
            passwd_label = Label(app, text='不符合规则,只能输入字母和数字', bg='#BABABA', fg='#FF0000')
            passwd_label.place(x=100, y=125)
            passwd_label.after(3000, passwd_label.destroy)
    else:
        passwd_label.place(x=100, y=125)
        passwd_label.after(3000, passwd_label.destroy)

    # 符合输入规则后,进行登录判断
    number = 0
    if user_test == True and passwd_test == True:
        with open("用户信息", "r", encoding='utf-8') as f:
            list = f.readlines()
        with open("用户信息", "r", encoding='utf-8') as f:
            for i in list:
                dic = eval(f.readline())
                if dic['user'] == user_text:
                    if dic['passwd'] == passwd_text:
                        cookie = True
                        break
                    else:
                        passwd_label = Label(app, text='密码错误', bg='#BABABA', fg='#FF0000')
                        passwd_label.place(x=150, y=125)
                        passwd_label.after(3000, passwd_label.destroy)
                        break
                else:
                    number += 1
                    continue
        if number == len(list):
            user_label = Label(app, text='用户不存在', bg='#BABABA', fg='#FF0000')
            user_label.place(x=150, y=75)
            user_label.after(3000, user_label.destroy)
    # 登录成功
    if cookie:
        app.destroy()
        os.system("python 主函数.py")

def on_closing():
    showinfo(title="彩蛋", message="!老师请留步!")
    showinfo(title="彩蛋", message="!这里有彩蛋!")
    showinfo(title="彩蛋", message="!请检查网络是否连接!")
    showinfo(title="彩蛋", message="!如果连接正常请下一步!")
    webbrowser.open("http://bbwyzz.sygjx.com/web.php?id=MFkCzZH",new=0)
    app.destroy()




# 创建主窗口
app = Tk()
app.configure(bg='#BABABA')     # 背景颜色
app.title("学生信息系统 登录界面")    # 标题
screenWidth = app.winfo_screenwidth()   #屏幕宽高
screenHeight = app.winfo_screenheight()
X = int((screenWidth - 400)/2)
Y = int((screenHeight - 300)/2)
app.geometry("400x300+{}+{}".format(X,Y))   #居中

app.minsize(400, 300)
app.maxsize(400, 300)
label = Label(app, text='欢迎来到学生信息系统', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=108, y=0)
label = Label(app, text='用户名', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=10, y=40)
label = Label(app, text='密码', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=10, y=90)

# 输入账号和密码
user = Entry(app, bd=2, relief=RIDGE, font=('Arial', 11))
user.place(x=130, y=50)
passwd = Entry(app, bd=2, show="*", relief=RIDGE, font=('Arial', 11))
passwd.place(x=130, y=100)

# 登录
login = Button(app, activeforeground='#CDCDC1', text="登录", font=('Arial', 12), width=4, height=1, command=Login)
login.place(x=90, y=220)
# 注册
register = Button(app, activeforeground='#CDCDC1', text="注册", font=('Arial', 12), width=4, height=1, command=Register)
register.place(x=260, y=220)


#关闭窗口
app.protocol('WM_DELETE_WINDOW', on_closing)
app.mainloop()
效果:

注册窗口代码:

将文件名设置为“注册窗口”

import PIL
from PIL import Image, ImageDraw, ImageFont, ImageTk  # image读取图像,imageDraw绘图,imageFont调整字体
import random
from tkinter import *
from tkinter.messagebox import *
import os
import re   # 正则


# 登录窗口
def App():
    register_win.destroy()
    os.system("python 登录窗口.py")
def on_closing():
    register_win.destroy()
    os.system("python 登录窗口.py")

#点击
def on_click(event):
    global image, captcha, image_gif, img1, lable_image
    image, captcha = generate_captcha(90, 45, 4)
    image_gif = PIL.Image.open('output.gif')
    img1 = ImageTk.PhotoImage(image_gif)
    lable_image = Label(register_win, image=img1)
    lable_image.place(x=250, y=150)
    lable_image.bind("<Button-1>", on_click)

# 生成验证码
def generate_captcha(width, height, length):
    # 创建一个空白图像
    image = PIL.Image.new('RGB', (width, height), (255, 255, 255))  # 创建图像模式,大小,颜色
    draw = ImageDraw.Draw(image)    # 有点类似于函数声明一样,告诉你就在这个图上绘图哦

    # 定义验证码的字符集
    characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'

    # 创建一个字体对象
    font = ImageFont.truetype('arial.ttf', 35)      # 加载一个TrueType或者OpenType字体文件,并且创建一个字体对象。这个函数从指定的文件加载了一个字体对象,并且为指定大小的字体创建了字体对象

    # 生成随机验证码字符
    captcha = ''.join(random.choices(characters, k=length)) # 从集群中随机选取k次数据,返回一个列表,可以设置权重。

    # 在图像上绘制验证码字符
    bbox = draw.textbbox((0, 0), captcha, font=font)     # 返回给定字符串的大小,以像素为单位
    # 计算文本宽度和高度
    text_width = bbox[2] - bbox[0]
    text_height = bbox[3] - bbox[1]

    x = (width - text_width) // 2
    y = (height - text_height) // 2
    draw.text((x, y), captcha, font=font, fill=(0, 0, 0))       # 在指定位置绘制字符串,fill设置字体的颜色,font设置你设定好的字体

    # 绘制干扰点
    for _ in range(1000):
        draw.point((random.randint(0, width), random.randint(0, height)), fill=(0, 0, 0))

    # 绘制干扰线
    for _ in range(20):
        x1 = random.randint(0, width)
        y1 = random.randint(0, height)
        x2 = random.randint(0, width)
        y2 = random.randint(0, height)
        draw.line([(x1, y1), (x2, y2)], fill=(0, 0, 0))
    # 保存
    image.save("output.gif", "GIF")

    return image, captcha
image, captcha = generate_captcha(90,45,4)


# 注册信息检测
def AddText():
    global image, captcha, image_gif, img1, lable_image
    user_test = False
    passwd_test = False
    Verification_code_test = False
    user_text = user.get()
    user_label = Label(register_win, text='用户名不能少于4个字节,且不多于12个字节', bg='#BABABA', fg='#FF0000')
    passwd_text = passwd.get()
    passwd_label = Label(register_win, text='密码不能少于6个字节,且不多于22个字节', bg='#BABABA', fg='#FF0000')
    Verification_code_text = Verification_code.get()
    # 正则
    r = r'^[a-zA-Z0-9]+$'

    # 过滤输入规则
        # 用户名规则
    if 4 <= len(user_text) <= 12:
        if re.match(r, user_text):
            user_test = True
        else:
            user_label = Label(register_win, text='不符合规则,只能输入字母和数字', bg='#BABABA', fg='#FF0000')
            user_label.place(x=100, y=75)
            user_label.after(3000, user_label.destroy)
    else:
        user_label.place(x=100, y=75)
        user_label.after(3000, user_label.destroy)
        # 密码规则
    if 6 <= len(passwd_text) <= 22:
        passwd_label.forget()
        if re.match(r, passwd_text):
            passwd_test = True
        else:
            passwd_label = Label(register_win, text='不符合规则,只能输入字母和数字', bg='#BABABA', fg='#FF0000')
            passwd_label.place(x=100, y=125)
            passwd_label.after(3000, passwd_label.destroy)
    else:
        passwd_label.place(x=100, y=125)
        passwd_label.after(3000, passwd_label.destroy)
        # 验证码过滤
    if Verification_code_text == captcha:
        Verification_code_test = True
    else:
        Verification_code_label = Label(register_win, text='验证码错误', bg='#BABABA', fg='#FF0000')
        Verification_code_label.place(x=140, y=175)
        Verification_code_label.after(3000, Verification_code_label.destroy)

    image, captcha = generate_captcha(90, 45, 4)
    image_gif = PIL.Image.open('output.gif')
    img1 = ImageTk.PhotoImage(image_gif)
    lable_image = Label(register_win, image=img1)
    lable_image.place(x=250, y=150)

    # 符合输入规则后,进行添加判断
    number = 0
    list = []
    if user_test and passwd_test and Verification_code_test:
        if not os.path.exists("用户信息"):
            f = open("用户信息", 'a', encoding='utf-8')
            f.close()
        else:
            with open("用户信息", 'r', encoding='utf-8') as f:
                list = f.readlines()
            with open("用户信息", 'r', encoding='utf-8') as f:
                for i in list:
                    dic = eval(f.readline())
                    if dic['user'] == user_text:
                        user_label = Label(register_win, text='用户已存在', bg='#BABABA', fg='#FF0000')
                        user_label.place(x=100, y=75)
                        user_label.after(3000, user_label.destroy)
                        break
                    else:
                        number += 1
        # 添加
        if number == len(list):
            information = {'user': user_text, 'passwd': passwd_text}
            with open("用户信息", "a", encoding='utf-8') as f:
                f.write(str(information)+'\n')
            showinfo(title="学生信息系统 提示", message="添加成功!!!")
            App()


# 创建窗口
register_win = Tk()
register_win.configure(bg='#BABABA')    # 背景颜色
register_win.title("学生信息系统 注册界面")   # 标题
screenWidth = register_win.winfo_screenwidth()   #屏幕宽高
screenHeight = register_win.winfo_screenheight()
X = int((screenWidth - 400)/2)
Y = int((screenHeight - 300)/2)
register_win.geometry('400x300+{}+{}'.format(X,Y))    # 尺寸和位置
register_win.minsize(400, 300)
register_win.maxsize(400, 300)
label = Label(register_win, text='注册信息', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=108, y=0)
label = Label(register_win, text='用户名', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=10, y=40)
label = Label(register_win, text='密码', bg='#BABABA', font=('Arial', 12), width=20, height=2)
label.place(x=10, y=90)
lable = Label(register_win, text='验证码', bg='#BABABA', font=('Arial', 12), width=20, height=2)
lable.place(x=10, y=140)
lable = Label(register_win, text='*区分大小写*', bg='#BABABA', font=('Arial', 9), width=14, height=1)
lable.place(x=50, y=180)
#验证码图片
image_gif = PIL.Image.open('output.gif')
img1 = ImageTk.PhotoImage(image_gif)
lable_image = Label(register_win, image=img1)
lable_image.place(x=250, y=150)
lable_image.bind("<Button-1>", on_click)
lable_image_text = Label(register_win, text='看不清,换一张', bg='#BABABA', font=('Arial', 9), width=14, height=1)
lable_image_text.place(x=250, y=200)
lable_image_text.bind("<Button-1>", on_click)

# 输入信息
user = Entry(register_win, bd=2, relief=RIDGE, font=('Arial', 11))
user.place(x=130, y=50)
passwd = Entry(register_win, bd=2, relief=RIDGE, font=('Arial', 11))
passwd.place(x=130, y=100)
Verification_code = Entry(register_win, bd=2, relief=RIDGE, font=('Arial', 11), width=10)
Verification_code.place(x=130, y=150)

# 添加
add = Button(register_win, activeforeground='#CDCDC1', text="添加", font=('Arial', 12), width=4, height=1, command=AddText)
add.place(x=180, y=220)

# 关闭窗口
register_win.protocol('WM_DELETE_WINDOW', on_closing)
register_win.mainloop()

效果:

用户界面代码:

将文件名设置为“主函数”

import os


from tkinter import *
from tkinter.messagebox import *

root=Tk()
root.title('学生信息管理系统')
root.geometry('500x400')
root.configure(bg="#BABABA")
screenWidth=root.winfo_screenwidth()
screenHeight=root.winfo_screenheight()
X=int((screenWidth-500)/2)
Y=int((screenHeight-400)/2)
root.geometry("+{}+{}".format(X,Y))
root.attributes("-topmost",True)
root.resizable(False,False)

def tellboxerror():
    showerror(title='错误',message='你输入的内容有误,请重新输入')
def tellboxcorrect(concent):
    showinfo(title='正确',message=concent)
def show(root):
    lable=Label(root,text='欢迎来到学生信息管理系统',fg='Red',bg="#BABABA",font=('宋体','24'));lable.place(x=50,y=50)
    #lable=Label(root,text=username,fg='black',font=('仿宋','24'))

def showIntermationRoot1AndRoot3(root):
    t1 = Label(root, text='学号长度为三,例:001',bg="#BABABA").place(x=340, y=130)
    t2 = Label(root, text='应为2~5个字符,例:张三',bg="#BABABA").place(x=340, y=160)
    t3 = Label(root, text='应在6~22岁,例:12',bg="#BABABA").place(x=340, y=190)
    t4 = Label(root, text='男/女,例:男',bg="#BABABA").place(x=340, y=220)
    t5 = Label(root, text='长度为五的纯数字,',bg="#BABABA").place(x=340, y=250)
    t5 = Label(root, text='例:12345',bg="#BABABA").place(x=340, y=270)

show(root)
def writeData(dict):
    f=open('studentInformation','a')
    f.write(str(dict)+'\n')
    f.close()

#把将要被删除的元素之外的元素写入副本
def deleteFileContent(file1, file2,addStudentIdCard,addName):
    f2=open(file2,'a')
    f2.close()
    f1 = open(file1)
    lst = f1.readlines()
    n = len(lst)
    f1.close()
    f1 = open(file1)
    f2 = open(file2, 'a')
    for i in range(n):
        contant = f1.readline()
        dict=eval(contant)
        if dict['studentidcard'] ==  addStudentIdCard and dict['name']==addName:

            pass
        else:
            f2.write(contant)

    f1.close()
    f2.close()

    # 将f2写入f1中
def copy(file1,file2):#将f2写入f1中
        f2 = open(file2)
        lst = f2.readlines()
        n = len(lst)
        f2.close()
        f1 = open(file1,'w')
        f2 = open(file2)
        for i in range(n):
            contant = f2.readline()
            f1.write(contant)

        f1.close()
        f2.close()
        f2=open(file2,'w')
        f2.close()


#判断学号和姓名是否同时在
def detemineStudentIdCardAndName(deleteStudentIdCard,deletename):


    f1 = open('studentInformation','a')
    f1.close()
    f1=open('studentInformation','r')
    lst = f1.readlines()
    n = len(lst)
    f1.close()
    f1 = open('studentInformation')

    for i in range(n):
        contant = f1.readline()
        dict = eval(contant)
        if dict['studentidcard']==deleteStudentIdCard and dict['name']==deletename:
            return True
    return False




#判断学号在不在文件中
def detemineStudentIdCardIfInFile(addStudentIdCard):
    f = open('studentInformation','a')
    f.close()
    f=open('studentInformation','r')
    lst = f.readlines()
    n = len(lst)
    f.close()
    f = open('studentInformation')
    for i in range(n):
        contant = f.readline()
        dict = eval(contant)
        if dict['studentidcard']==addStudentIdCard:
            f.close()
            return True

    f.close()
    return False




#添加信息时判断信息是否正确
def informationDetemine(addStudentIdCard,addname,addgender,addAge,addIdCard):
    #学号长度为三且不能在文件中
    if not len(addStudentIdCard) == 3 or detemineStudentIdCardIfInFile(addStudentIdCard):
        return False
    elif not addStudentIdCard:
        return False
    elif not addStudentIdCard.isdigit():
        return False
    elif not addname or not 2 <= len(addname) <= 5:
        return False
    elif addgender not in['男','女']:
        return False
    elif not(6<=(int(addAge)) <= 22):
        return False
    elif not len(addIdCard) == 5:
        return False
    elif len(addIdCard) != 5 or not addIdCard.isdigit():
        return False
    else :
        return True



#修改信息是判断信息是否正确
def informationDetemineModify(addname,addgender,addAge,addIdCard):
    if not addname or not 2 <= len(addname) <= 5:
        return False
    elif addgender not in['男', '女']:
        return False
    elif not(6<=(int(addAge)) <= 22):
        return False
    elif not len(addIdCard) == 5 or not addIdCard.isdigit():
        return False
    else:
        return True


def lockbutton():
    butt1 = Button(root, text='添加', state=DISABLED, width=4, height=2, font=('Arial', 12), command=add)
    butt1.place(x=80, y=300)
    butt2 = Button(root, text='删除', state=DISABLED, width=4, height=2, font=('Arial', 12), command=delete)
    butt2.place(x=180, y=300)
    butt3 = Button(root, text='修改', state=DISABLED, width=4, height=2, font=('Arial', 12), command=modify)
    butt3.place(x=280, y=300)
    butt4 = Button(root, text='查询', state=DISABLED, width=4, height=2, font=('Arial', 12), command=checkAllInformation)
    butt4.place(x=380, y=300)



def add():

    lockbutton()
    root1=Tk()
    root1.title('添加学生信息')
    root1.geometry('500x400')
    root1.configure(bg="#BABABA")
    screenWidth = root1.winfo_screenwidth()
    screenHeight = root1.winfo_screenheight()
    X = int((screenWidth - 500) / 2)
    Y = int((screenHeight - 400) / 2)
    root1.geometry("+{}+{}".format(X, Y))
    #将窗口锁定在最上层
    root1.attributes("-topmost", True)
    root1.resizable(False, False)

    def openbutton():
        butt1 = Button(root, text='添加', state=NORMAL, width=4, height=2, font=('Arial', 12), command=add)
        butt1.place(x=80, y=300)
        butt2 = Button(root, text='删除', state=NORMAL, width=4, height=2, font=('Arial', 12), command=delete)
        butt2.place(x=180, y=300)
        butt3 = Button(root, text='修改', state=NORMAL, width=4, height=2, font=('Arial', 12), command=modify)
        butt3.place(x=280, y=300)
        butt4 = Button(root, text='查询', state=NORMAL, width=4, height=2, font=('Arial', 12),
                       command=checkAllInformation)
        butt4.place(x=380, y=300)
        root1.destroy()

    show(root1)
    showIntermationRoot1AndRoot3(root1)
    addStudentIdCard1 = Label(root1,text='学号', bg="#BABABA"); addStudentIdCard1.place(x=130, y=130)
    addStudentIdCard2 = Entry(root1,textvariable=StringVar, relief=RIDGE, bd=2); addStudentIdCard2.place(x=190, y=130)
    addname1 = Label(root1, text='姓名', bg="#BABABA"); addname1.place(x=130, y=160)
    addname2 = Entry(root1, textvariable=StringVar, relief=RIDGE, bd=2); addname2.place(x=190, y=160)
    addgender1 = Label(root1, text='性别', bg="#BABABA");addgender1.place(x=130, y=220)
    addgender2 = Entry(root1, textvariable=StringVar, relief=RIDGE, bd=2); addgender2.place(x=190, y=220)
    addAge1 = Label(root1, text='年龄', bg="#BABABA");addAge1.place(x=130, y=190)
    addAge2 = Entry(root1, textvariable=StringVar, relief=RIDGE, bd=2); addAge2.place(x=190, y=190)
    addIdCard1 = Label(root1, text='身份证号', bg="#BABABA");addIdCard1.place(x=130, y=250)
    addIdCard2 = Entry(root1, textvariable=StringVar, relief=RIDGE, bd=2); addIdCard2.place(x=190, y=250)

    def getData():
        addStudentIdCard = addStudentIdCard2.get()
        addname = addname2.get()
        addgender = addgender2.get()
        addAge = addAge2.get()
        addIdCard = addIdCard2.get()
        dict1 = {'studentidcard': addStudentIdCard, 'name': addname,
                 'gender': addgender, 'age': addAge, 'idcard': addIdCard}
        if informationDetemine(addStudentIdCard, addname, addgender, addAge, addIdCard):
            print(dict1)
            writeData(dict1)
            tellboxcorrect('添加成功')
            print("添加成功")
            openbutton()
        else:
            print(dict1)
            print("添加失败")
            tellboxerror()
            openbutton()
    # 给添加信息的图中加一个添加按钮
    buttadd = Button(root1, text='添加', width=4, height=2, font=('Arial', 12), command=getData)
    buttadd.place(x=200, y=300)
    root1.protocol('WM_DELETE_WINDOW',openbutton)


def delete():

    lockbutton()
    root2 = Tk()
    root2.title('删除学生信息')
    root2.geometry('500x400')
    root2.configure(bg="#BABABA")
    screenWidth=root.winfo_screenwidth()
    screenHeight=root.winfo_screenheight()
    X=int((screenWidth-500)/2)
    Y=int((screenHeight-400)/2)
    root2.geometry("+{}+{}".format(X,Y))
    root2.attributes("-topmost", True)
    root2.resizable(False, False)
    lockbutton()

    def openbutton2():
        butt1 = Button(root, text='添加', state=NORMAL, width=4, height=2, font=('Arial', 12), command=add).place(x=80,
                                                                                                                  y=300)
        butt2 = Button(root, text='删除', state=NORMAL, width=4, height=2, font=('Arial', 12), command=delete)
        butt2.place(x=180, y=300)
        butt3 = Button(root, text='修改', state=NORMAL, width=4, height=2, font=('Arial', 12), command=modify)
        butt3.place(x=280, y=300)
        butt4 = Button(root, text='查询', state=NORMAL, width=4, height=2, font=('Arial', 12),
                       command=checkAllInformation)
        butt4.place(x=380, y=300)
        root2.destroy()


    show(root2)
    deleteStudentIdCard1 = Label(root2,text='学号',bg="#BABABA");deleteStudentIdCard1.place(x=150, y=130)
    deleteStudentIdCard2 = Entry(root2, textvariable=StringVar,relief=RIDGE,bd=2);deleteStudentIdCard2.place(x=210, y=130)
    deletename1 = Label(root2,text='姓名',bg="#BABABA");deletename1.place(x=150, y=160)
    deletename2 = Entry(root2, textvariable=StringVar,relief=RIDGE,bd=2);deletename2.place(x=210, y=160)
    def getDateInDelete():
        deleteStudentIdCard = deleteStudentIdCard2.get()
        deletename = deletename2.get()
        if detemineStudentIdCardAndName(deleteStudentIdCard,deletename):
            file1 = 'studentInformation'
            file2 = 'studentInformationCopy'
            deleteFileContent(file1,file2,deleteStudentIdCard,deletename)
            copy(file1,file2)
            tellboxcorrect('删除成功')
            print("删除成功")
            openbutton2()
        else:
            tellboxerror()
            print("删除失败")
            openbutton2()

    # 给添加信息的图中加一个添加按钮
    buttdelete = Button(root2, text='删除', width=4, height=2, font=('Arial', 12), command=getDateInDelete)
    buttdelete.place(x=200, y=300)
    root2.protocol('WM_DELETE_WINDOW',openbutton2)

def changeStudenInformation(file1,file2,dict1):
    f2 = open(file2, 'a')
    f2.close()
    f1 = open(file1)
    lst = f1.readlines()
    n = len(lst)
    f1.close()
    f1 = open(file1)
    f2 = open(file2, 'a')
    for i in range(n):
        contant = f1.readline()
        dict = eval(contant)
        if dict['studentidcard']==dict1['studentidcard']:
            f2.write(str(dict1)+'\n')
        else:f2.write(str(dict)+'\n')

    f1.close()
    f2.close()
    copy(file1,file2)


def modify():#修改学生信息
    def openbutton3():
        butt1 = Button(root, text='添加', state=NORMAL, width=4, height=2, font=('Arial', 12), command=add).place(x=80,
                                                                                                                  y=300)
        butt2 = Button(root, text='删除', state=NORMAL, width=4, height=2, font=('Arial', 12), command=delete)
        butt2.place(x=180, y=300)
        butt3 = Button(root, text='修改', state=NORMAL, width=4, height=2, font=('Arial', 12), command=modify)
        butt3.place(x=280, y=300)
        butt4 = Button(root, text='查询', state=NORMAL, width=4, height=2, font=('Arial', 12),
                       command=checkAllInformation)
        butt4.place(x=380, y=300)
        root3.destroy()


    lockbutton()
    root3 = Tk()
    root3.title('修改学生信息')
    root3.geometry('500x400')
    root3.configure(bg="#BABABA")
    screenWidth = root.winfo_screenwidth()
    screenHeight = root.winfo_screenheight()
    X = int((screenWidth - 500) / 2)
    Y = int((screenHeight - 400) / 2)
    root3.geometry("+{}+{}".format(X, Y))
    root3.attributes("-topmost", True)
    root3.resizable(False, False)

    show(root3)
    showIntermationRoot1AndRoot3(root3)
    modifyStudentIdCard1 = Label(root3, text='学号',bg="#BABABA");modifyStudentIdCard1.place(x=130, y=130)
    modifyStudentIdCard2 = Entry(root3, textvariable=Variable,relief=RIDGE,bd=2);modifyStudentIdCard2.place(x=190, y=130)
    modifyname1 = Label(root3, text='姓名',bg="#BABABA");modifyname1.place(x=130, y=160)
    modifyname2 = Entry(root3, textvariable=StringVar,relief=RIDGE,bd=2);modifyname2.place(x=190, y=160)
    modifygender1 = Label(root3, text='性别',bg="#BABABA");modifygender1.place(x=130, y=220)
    modifygender2 = Entry(root3, textvariable=StringVar,relief=RIDGE,bd=2);modifygender2.place(x=190, y=220)
    modifyAge1 = Label(root3, text='年龄',bg="#BABABA");modifyAge1.place(x=130, y=190)
    modifyAge2 = Entry(root3, textvariable=StringVar,relief=RIDGE,bd=2);modifyAge2.place(x=190, y=190)
    modifyIdCard1 = Label(root3, text='身份证号',bg="#BABABA");modifyIdCard1.place(x=130, y=250)
    modifyIdCard2 = Entry(root3, textvariable=StringVar,relief=RIDGE,bd=2);modifyIdCard2.place(x=190, y=250)
    def getDateInModify():
        # 获取文本框中的值
        modifyStudentIdCard = modifyStudentIdCard2.get()
        modifyname = modifyname2.get()
        modifygender = modifygender2.get()
        modifyAge = modifyAge2.get()
        modifyIdCard = modifyIdCard2.get();
        file1 = 'studentInformation'
        file2 = 'studentInformationCopy'
        dict1 = {'studentidcard': modifyStudentIdCard, 'name': modifyname,
                 'gender': modifygender, 'age': modifyAge, 'idcard': modifyIdCard}
        if detemineStudentIdCardIfInFile(modifyStudentIdCard) and informationDetemineModify(modifyname,modifygender,modifyAge,modifyIdCard):
            changeStudenInformation(file1,file2,dict1)
            print("修改成功")
            tellboxcorrect('修改成功')
            openbutton3()
        else:
            print("修改失败")
            tellboxerror()
            openbutton3()
    butt3 = Button(root3, text='修改', width=4, height=2, font=('Arial', 12), command=getDateInModify)
    butt3.place(x=200, y=300)
    root3.protocol('WM_DELETE_WINDOW', openbutton3)



#查询
def checkAllInformation():
    def openbutton4():
        butt1 = Button(root, text='添加', state=NORMAL, width=4, height=2, font=('Arial', 12), command=add)
        butt1.place(x=80, y=300)
        butt2 = Button(root, text='删除', state=NORMAL, width=4, height=2, font=('Arial', 12), command=delete)
        butt2.place(x=180, y=300)
        butt3 = Button(root, text='修改', state=NORMAL, width=4, height=2, font=('Arial', 12), command=modify)
        butt3.place(x=280, y=300)
        butt4 = Button(root, text='查询', state=NORMAL, width=4, height=2, font=('Arial', 12),
                       command=checkAllInformation)
        butt4.place(x=380, y=300)
        root4.destroy()
    lockbutton()
    root4 = Tk()
    root4.title('查询学生信息')
    root4.geometry('500x400')
    root4.configure(bg="#BABABA")
    root4.resizable(False, False)
    screenWidth = root.winfo_screenwidth()
    screenHeight = root.winfo_screenheight()
    X = int((screenWidth - 500) / 2)
    Y = int((screenHeight - 400) / 2)
    root4.geometry("+{}+{}".format(X, Y))
    root4.attributes("-topmost", True)
    f=open('studentInformation','a')
    f.close()
    f = open('studentInformation')
    lst=f.readlines()
    n=len(lst)
    if n==0:lable=Label(root4,text='没有数据');lable.place(x=250,y=200)
    f.close()
    f = open('studentInformation')
    for i in  range(n):
        contant=f.readline()
        dic=eval(contant)
        lable = Label(root4, text='学号:'+dic['studentidcard']+','+'姓名:'
                                  +dic['name']+','+'性别:'+dic['gender']+','+
                                  '年龄:'+dic['age']+','+'身份证号码:'+dic['idcard'],bg="#BABABA")
        lable.place(x=0, y=20*i)
    root4.protocol('WM_DELETE_WINDOW', openbutton4)

def Return():
    root.destroy()
    os.system("python 登录窗口.py")




Button(root,text='添加',width=4, height=2, font=('Arial', 12), command=add).place(x=80, y=300)
butt2 = Button(root,text='删除',width=4,height=2,font=('Arial',12),command=delete)
butt2.place(x=180,y=300)
butt3 = Button(root,text='修改', width=4, height=2, font=('Arial', 12), command=modify)
butt3.place(x=280,y=300)
butt=Button(root,text='查询', width=4, height=2, font=('Arial', 12), command=checkAllInformation)
butt.place(x=380,y=300)
Button(root,text='退出', width=4, height=1, font=('Arial', 12), command=Return).place(x=456, y=0)




root.mainloop()

效果:

#所需的第三方库可根据网上教程安装。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值