tkinter学生管理系统

import tkinter as tk
import tkinter.messagebox
from tkinter import messagebox
def read():
    p1 = []
    p2 = []
    f = open("./test.txt", 'r', encoding='utf-8')
    for i in f:
        # 每行的末尾都有一个换行符把换行符去掉
        i = i.replace('\n', '')
        b = i.split("\t")
        # 将i中的字符串以一个分隔符的大小存储在列表中
        # 学号  名字  身高 体重  性别
        p1.append(b)
        # 将列表b存放到列表p1中p1=【【b1】,【b2】...】
        dic = {}
        for j in range(0,len(p1)):
            dic["学号(限10位)"] = p1[j][0]
            dic["名字"] = p1[j][1]
            dic["身高(cm)"] = p1[j][2]
            dic["体重(kg)"] = p1[j][3]
            dic["性别"] = p1[j][4]
        # 将所有信息都存储到字典中
        p2.append(dic)
    # 将字典dic存储到列表中当作元素[{dic1},{dic2}....]
    return p2
# new是一个经过更改后的列表存储了所需要的文档txt
def write(new):
    f = open('test.txt', 'w', encoding="utf-8")
    for i in new:
        a = i
        # a是每一个键值对例如:学号 “2208114260”
        # i是列表里的字典
        f.write("{}\t{}\t{}\t{}\t{}\n".format(a["学号(限10位)"], a["名字"], a["身高(cm)"], a["体重(kg)"], a["性别"]))



def warn1():
    #学号错误
    a = tkinter.messagebox.showerror(title="输入错误", message="学号输入错误!!!")
def warn2():
    #身高错误
    a = tkinter.messagebox.showerror(title="输入错误", message="身高输入错误!!!")
def warn3():
    a = tkinter.messagebox.showerror(title="输入错误", message="体重输入错误!!!")
def warn4():
    a = tkinter.messagebox.showerror(title="输入错误", message="性别输入错误!!!")

def change():
    def change1():
        def change2(pist):
            def change3():
                if entry55.get() != "男" and entry55.get() != '女':
                    warn4()
                elif entry11.get() != 10:
                    warn1()
                elif int(entry22.get()) < 150 or int(entry22.get()) > 220:
                    warn2()
                elif int(entry33.get()) < 40 or int(entry33.get()) > 120:
                    warn3()
                else:
                    a1 = entry11.get()
                    b1 = entry22.get()
                    c1 = entry33.get()
                    d1 = entry44.get()
                    e1 = entry55.get()
                    pist["学号(限10位)"] = a1
                    pist["名字"] = b1
                    pist["身高(cm)"] = c1
                    pist["体重(kg)"] = d1
                    pist["性别"] = e1
                    back21.destroy()
                    write(box)
                    back1.destroy()
            back21 = tk.Tk()
            back21.geometry("500x650")
            back21.title("修改")
            frame111 = tk.Frame(back21)
            frame111.pack()
            label11 = tk.Label(frame111, text="学号(限10位)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
            label11.pack()
            entry11 = tk.Entry(frame111, font=("Arial", 12), width=15, bg="pink", fg="blue")
            entry11.pack()

            frame122 = tk.Frame(back21)
            frame122.pack()
            label22 = tk.Label(frame122, text="名字", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
            label22.pack()
            entry22 = tk.Entry(frame122, font=("Arial", 12), width=15, bg="pink", fg="blue")
            entry22.pack()

            frame133 = tk.Frame(back21)
            frame133.pack()
            label33 = tk.Label(frame133, text="身高(cm)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
            label33.pack()
            entry33 = tk.Entry(frame133, font=("Arial", 12), width=15, bg="pink", fg="blue")
            entry33.pack()

            frame144 = tk.Frame(back21)
            frame144.pack()
            label44 = tk.Label(frame144, text="体重(kg)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
            label44.pack()
            entry44 = tk.Entry(frame144, font=("Arial", 12), width=15, bg="pink", fg="blue")
            entry44.pack()

            frame155 = tk.Frame(back21)
            frame155.pack()
            label55 = tk.Label(frame155, text="性别", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
            label55.pack()
            entry55 = tk.Entry(frame155, font=("Arial", 12), width=15, bg="pink", fg="blue")
            entry55.pack()

            frame166 = tk.Frame(back21)
            frame166.pack()
            label66 = tk.Label(frame166, font=("Arial", 15), width=15, height=3, fg="white")
            label66.pack()
            button1111 = tk.Button(back21, fg="blue", font=("Arial", 12), text="确定", width=15, height=3,
                                   command=change3)
            button1111.pack()
            back21.mainloop()

        box = []
        a = entry1.get()
        b = entry2.get()
        box = read()
        for i in box:
            if i["学号(限10位)"] == a or i["名字"] == b:
                if len(entry1.get()) != 10:
                    warn1()
                else:
                    change2(i)

    back1 = tk.Tk()
    back1.geometry("500x450")
    back1.title("修改")
    frame11 = tk.Frame(back1)
    frame11.pack()
    label1 = tk.Label(frame11, text="学号(限10位)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label1.pack()
    entry1 = tk.Entry(frame11, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry1.pack()

    frame12 = tk.Frame(back1)
    frame12.pack()
    label2 = tk.Label(frame12, text="名字", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label2.pack()
    entry2 = tk.Entry(frame12, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry2.pack()

    frame16 = tk.Frame(back1)
    frame16.pack()
    label6 = tk.Label(frame16, font=("Arial", 15), width=15, height=3, fg="white")
    label6.pack()
    button11 = tk.Button(back1, fg="blue", font=("Arial", 12), text="修改", width=15, height=3, command=change1)
    button11.pack()
    t = tk.Label(back1, font=("Arial", 15), width=40, height=3,text="输入学号或者姓名进行修改")
    t.pack()
    back1.mainloop()


def add1():
    def load():
        if len(entry1.get()) != 10:
            warn1()
        elif int(entry3.get()) < 150 or int(entry3.get()) > 220:
            warn2()
        elif entry5.get() != '男' and entry5.get() != '女':
            warn4()
        elif int(entry4.get()) < 40 or int(entry4.get()) > 120:
            warn3()
        else:
            box = []
            a = entry1.get()
            b = entry2.get()
            c = entry3.get()
            d = entry4.get()
            e = entry5.get()
            dict2 = {"学号(限10位)": a, "名字": b, "身高(cm)": c, "体重(kg)": d, "性别": e}
            box = read()
            box.append(dict2)
            write(box)
            back1.destroy()
    back1 = tk.Tk()
    back1.geometry("500x650")
    back1.title("添加")
    frame11 = tk.Frame(back1)
    frame11.pack()
    label1 = tk.Label(frame11, text="学号(限10位)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label1.pack()
    entry1 = tk.Entry(frame11, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry1.pack()

    frame12 = tk.Frame(back1)
    frame12.pack()
    label2 = tk.Label(frame12, text="名字", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label2.pack()
    entry2 = tk.Entry(frame12, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry2.pack()

    frame13 = tk.Frame(back1)
    frame13.pack()
    label3 = tk.Label(frame13, text="身高(cm)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label3.pack()
    entry3 = tk.Entry(frame13, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry3.pack()

    frame14 = tk.Frame(back1)
    frame14.pack()
    label4 = tk.Label(frame14, text="体重(kg)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label4.pack()
    entry4 = tk.Entry(frame14, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry4.pack()

    frame15 = tk.Frame(back1)
    frame15.pack()
    label5 = tk.Label(frame15, text="性别", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label5.pack()
    entry5 = tk.Entry(frame15, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry5.pack()

    frame16 = tk.Frame(back1)
    frame16.pack()
    label6 = tk.Label(frame16, font=("Arial", 15), width=15, height=3, fg="white")
    label6.pack()
    button11 = tk.Button(back1, fg="blue", font=("Arial", 12), text="确定", width=15, height=3, command=load)
    button11.pack()
    back1.mainloop()
def delete():
    def find():
        box = []
        a = entry1.get()
        b = entry2.get()
        box = read()
        for i in box:
            if i["学号(限10位)"] == a or i["名字"] == b:
                box.remove(i)
        write(box)
        back1.destroy()
    back1 = tk.Tk()
    back1.geometry("500x450")
    back1.title("删除")
    frame11 = tk.Frame(back1)
    frame11.pack()
    label1 = tk.Label(frame11, text="学号(限10位)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label1.pack()
    entry1 = tk.Entry(frame11, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry1.pack()

    frame12 = tk.Frame(back1)
    frame12.pack()
    label2 = tk.Label(frame12, text="名字", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label2.pack()
    entry2 = tk.Entry(frame12, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry2.pack()

    frame16 = tk.Frame(back1)
    frame16.pack()
    label6 = tk.Label(frame16, font=("Arial", 15), width=15, height=3, fg="white")
    label6.pack()
    button11 = tk.Button(back1, fg="blue", font=("Arial", 12), text="确定", width=15, height=3, command=find)
    button11.pack()
    back1.mainloop()
def search():
    def find():
        def show(tap):
            back1.destroy()
            black = tk.Tk()
            black.geometry("400x400")
            black.title("查询成绩")
            board = tk.Frame(black)
            board.pack()
            pop = tk.Text(board, width=40, height=1, font=("Arial", 14, 'bold'))
            pop1 = tk.Text(board, width=40, height=1, font=("Arial", 14, 'bold'))
            pop2 = tk.Text(board, width=40, height=1, font=("Arial", 14, 'bold'))
            pop3 = tk.Text(board, width=40, height=1, font=("Arial", 14, 'bold'))
            pop4 = tk.Text(board, width=40, height=1, font=("Arial", 14, "bold"))
            pop.pack()
            pop1.pack()
            pop2.pack()
            pop3.pack()
            pop4.pack()

            pop.insert("end", "学号(限10位):")
            ap = i['学号(限10位)']
            pop.insert("end", ap)

            pop1.insert("end", "名字:")
            ap = i['名字']
            pop1.insert("end", ap)

            pop2.insert("end", "身高(cm):")
            ap = i['身高(cm)']
            pop2.insert("end", ap)

            pop3.insert("end", "体重(kg):")
            ap = i['体重(kg)']
            pop3.insert("end", ap)

            pop4.insert("end", "性别:")
            ap = i['性别']
            pop4.insert("end", ap)
            black.mainloop()

        box = []
        a = entry1.get()
        b = entry2.get()
        box = read()
        for i in box:
            if i["学号(限10位)"] == a or i["名字"] == b:
                show(i)


    back1 = tk.Tk()
    back1.geometry("500x450")
    back1.title("查询")
    frame11 = tk.Frame(back1)
    frame11.pack()
    label1 = tk.Label(frame11, text="学号(限10位)", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label1.pack()
    entry1 = tk.Entry(frame11, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry1.pack()

    frame12 = tk.Frame(back1)
    frame12.pack()
    label2 = tk.Label(frame12, text="名字", font=("Arial", 15, "bold"), width=15, height=3, fg="blue")
    label2.pack()
    entry2 = tk.Entry(frame12, font=("Arial", 12), width=15, bg="pink", fg="blue")
    entry2.pack()

    frame16 = tk.Frame(back1)
    frame16.pack()
    label6 = tk.Label(frame16, font=("Arial", 15), width=15, height=3, fg="white")
    label6.pack()
    button11 = tk.Button(back1, fg="blue", font=("Arial", 12), text="确定", width=15, height=3, command=find)
    button11.pack()
    back1.mainloop()
def show_all():
    all_list = read()
    black = tk.Tk()
    black.geometry("800x400")
    black.title("显示成绩")
    board = tk.Frame(black)
    board.pack()
    for j in range(0, len(all_list)):
            pop = tk.Text(board, width=80, height=1, font=("Arial", 14, 'bold'))
            i = all_list[j]
            pop.insert("end", "学号(限10位):")
            ap = i['学号(限10位)']
            pop.insert("end", ap)
            pop.insert("end", "     名字:")
            ap = i['名字']
            pop.insert("end", ap)
            pop.insert("end", "     身高(cm):")
            ap = i['身高(cm)']
            pop.insert("end", ap)
            pop.insert("end", "     体重(kg):")
            ap = i['体重(kg)']
            pop.insert("end", ap)
            pop.insert("end", "     性别:")
            ap = i['性别']
            pop.insert("end", ap)
            pop.pack()
    black.mainloop()

back = tk.Tk()
back.geometry("400x400")
back.title("学生管理系统")
frame1 = tk.Frame(back)
frame1.pack()
frame2 = tk.Frame(back)
frame2.pack()
frame3 = tk.Frame(back)
frame3.pack()
frame4 = tk.Frame(back)
frame4.pack()
frame5 = tk.Frame(back)
frame5.pack()
button1 = tk.Button(frame1, bg="pink", fg="blue", font=("Arial", 12), text="添加学生信息", width=15, height=3,
                    command=add1)
button1.pack()
button2 = tk.Button(frame2, bg="pink", fg="blue", font=("Arial", 12), text="删除学生信息", width=15, height=3,
                    command=delete)
button2.pack()
button3 = tk.Button(frame3, bg="pink", fg="blue", font=("Arial", 12), text="修改学生信息", width=15, height=3,
                    command=change)
button3.pack()
button4 = tk.Button(frame4, bg="pink", fg="blue", font=("Arial", 12), text="查询学生信息", width=15, height=3,
                    command=search)
button4.pack()
button5 = tk.Button(frame4, bg="pink", fg="blue", font=("Arial", 12), text="显示所有学生信息", width=15, height=3,
                    command=show_all)
button5.pack()
back.mainloop()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GG bond123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值