学生信息管理系统

学生信息管理系统


—————————————————————————————————

拿走不谢

代码1:

from Student import *

class StudentManager(object):
    def __init__(self):
        #存储数据所需列表
        self.student_list = []
        # self.load_student()


    #一,程序入口函数,启动程序后执行的函数

    def run(self):
        # 1.加载学员信息
        # self.load_student()

        while True:
            #2.显示功能菜单
            self.show_menu()
            # self.show_menu()
            #3.用户输入功能序号
            menu_num = int(input("请输入您需要的功能序号:"))
            #4.根据用用户输入的功能序号执行不同功能
            if menu_num == 1:
                #添加学员
                self.add_student()
            elif menu_num == 2:
                #删除学员
                self.del_student()
            elif menu_num == 3:
                #修改学员信息
                self.modify_student()
            elif menu_num == 4:
                #查询学员信息
                self.search_student()
            elif menu_num == 5:
                #显示所有学员信息
                self.show_student()
            elif menu_num == 6:
                #保存学员信息
                self.save_student()
            elif menu_num == 7:
                #退出系统
                break

    #二,系统功能函数
    #2.1 显示功能菜单   --打印序号对应的功能关系--  静态
    @staticmethod
    def show_menu():
        print('请选择如下功能:')
        print('1:添加学员')
        print('2:删除学员')
        print('3:修改学员信息')
        print('4:查询学员信息')
        print('5:显示所有学员信息')
        print('6:保存学员信息')
        print('7:退出系统')
    #2.2 添加学员
    def add_student(self):
        #1.添加姓名,性别,电话
        name = input("请输入您的姓名:")
        gender = input('请输入您的性别:')
        tel = input('请输入您的电话:')
        #2.创建学院对象  --类。在student中
        student = Student(name,gender,tel)
        #3.将该对象添加到学员列表
        self.student_list.append(student)
    #2.3 删除学员
    def del_student(self):
        #1.输入学员姓名
        del_name = input('请输入学员姓名:')
        #2.如果用户输入的目标学员存在则删除,否则提示学员不存在
        for i in self.student_list:
            if i.name == del_name:
                self.student_list.remove(i)
                break
        else:
            print('查无此人!')
    #2.4 修改学员信息
    def modify_student(self):
        #1.输入学员姓名:
        modify_name = input('请输入学员姓名:')
        #2.如果学员存在则进行修改,否则提示学员不存在
        for i in self.student_list:
            if modify_name == i.name:
                i.name = input("请输入学员姓名:")
                i.gender = input("请输入学院性别:")
                i.tel = input("请输入学员手机号:")
                print(f'修改该学员信息成功,姓名:{i.name},性别:{i.gender},手机号:{i.tel}')
                break
        else:
            print("查无此人!")
    #2.5 查询学员信息
    def search_student(self):
        # 1. ⽤户输⼊⽬标学员姓名
        search_name = input('请输⼊要查询的学员的姓名:')
        # 2. 如果⽤户输⼊的⽬标学员存在,则打印学员信息,否则提示学员不存在
        for i in self.student_list:
            if i.name == search_name:
                print(f'姓名{i.name},性别{i.gender}, ⼿机号{i.tel}')
                break
        else:
            print('查⽆此⼈!')
    #2.6 显示所有学员信息
    def show_student(self):
        print('姓名\t性别\t⼿机号')
        for i in self.student_list:
            print(f'{i.name}\t{i.gender}\t{i.tel}')
    #2.7 保存学员信息
    def save_student(self):
        # 1. 打开⽂件
        f = open('student.txt', 'w')
        # 2. ⽂件写⼊学员数据
        # 注意1:⽂件写⼊的数据不能是学员对象的内存地址,需要把学员数据转换成列表字典数据再做存储
        new_list = [i.__dict__ for i in self.student_list]
        # [{'name': 'aa', 'gender': 'nv', 'tel': '111'}]
        print(new_list)
        # 注意2:⽂件内数据要求为字符串类型,故需要先转换数据类型为字符串才能⽂件写⼊数据
        f.write(str(new_list))
        # 3. 关闭⽂件
        f.close()
    #2.8 加载学员信息
    def load_student(self):
        try:
            f = open('student.txt', 'r')
        except:
            f = open('student.txt', 'w')
        else:
            # 1. 读取数据
            data = f.read()
        # 2. ⽂件中读取的数据都是字符串且字符串内部为字典数据,故需要转换数据类型再转换字典为对象后存储到学员列表
            new_list = eval(data)
            self.student_list = [Student(i['name'], i['gender'], i['tel']) for i in new_list]
        finally:
        # 3. 关闭⽂件
            f.close()

代码2:

class Student(object):
    def __init__(self,name,gender,tel):
        #姓名性别手机号
        self.name = name
        self.gender = gender
        self.tel = tel
    def __str__(self):
        return f'{self.name},{self.gender},{self.tel}'

代码3:

from wwww import *
from tkinter import *
import tkinter as tk
from Student import *
window=tk.Tk()              #创建一个窗口
window.title("学生信息管理系统")     #window标题
window.geometry('800x500')  #定义window界面大小
#anchor:1. 控制文本(或图像)在 Label 中显示的位置
# 2. “n”, “ne”, “e”, “se”, “s”, “sw”, “w”, “nw”,
# 或者 “center” 来定位(ewsn 代表东西南北,上北下南左西右东)
# 3. 默认值是 “center”
#2.启动管理系统
#保存当前文件运行才启动管理系统:if --创建对象并调用run方法
try:
    f = open('student.txt', 'r')
except:
    f = open('student.txt', 'w')
else:
    # 1. 读取数据
    data = f.read()
    # 2. ⽂件中读取的数据都是字符串且字符串内部为字典数据,故需要转换数据类型再转换字典为对象后存储到学员列表
    new_list = eval(data)
    student_list = [Student(i['name'], i['gender'], i['tel']) for i in new_list]
finally:
    # 3. 关闭⽂件
    f.close()
def deng_lu():
    if mima1.get()=='1' and mima2.get()=='1':
        butten()
    else:
        text3 = tk.Label(window, text='密码错误')
        text3.place(x=395, y=205, anchor=NW)
def cup():
    window.destroy()  # 关掉之前的窗口
def isert_point():
    var = e.get()
    t.insert("insert",var)
def insert_end():
    var = e.get()
    # t.insert("end", var)       #添加至最后
    t.insert(2.2,var)       #添加至第二行的第二个元素的后面
def butten():
    window.destroy()  # 关掉之前的窗口
    windows = tk.Tk()  # 创建一个窗口
    windows.title("学生信息管理系统")  # window标题
    windows.geometry('800x500')  # 定义window界面大小

    def addname():
        def luru():
            name = name2.get()
            gender = nn2.get()
            tel = tel2.get()
            student = Student(name, gender, tel)
             # 3.将该对象添加到学员列表
            student_list.append(student)

        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        name2 = tk.Entry(windows, show="")
        name2.place(x=355, y=100, anchor=NW)
        nn2 = tk.Entry(windows, show="")
        nn2.place(x=355, y=150, anchor=NW)
        tel2 = tk.Entry(windows, show="")
        tel2.place(x=355, y=200, anchor=NW)
        name1 = tk.Label(windows, text='姓名')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='性别')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='手机号码')
        tel1.place(x=270, y=200, anchor=NW)
        BBB = tk.Button(windows, text="录入",command=luru)
        BBB.place(x=400, y=250, anchor=NW)

    def setname():
        def del_student():
            # 1.输入学员姓名
            del_name=usename2.get()
            # 2.如果用户输入的目标学员存在则删除,否则提示学员不存在
            for i in student_list:
                if i.name == del_name:
                    student_list.remove(i)
                    break
            else:
                name1 = tk.Label(windows, text='              查无此人!                 ')
                name1.place(x=270, y=100, anchor=NW)

        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='姓名')
        name1.place(x=270, y=100, anchor=NW)
        usename2 = tk.Entry(windows, show="")
        usename2.place(x=355, y=100, anchor=NW)
        name2 = tk.Entry(windows, show="")
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        BBB=tk.Button(windows,text="删除",command=del_student)
        BBB.place(x=400,y=250,anchor=NW)

    def changename():
        def modify_student():
            # 1.输入学员姓名:
            modify_name = usename2.get()
            # 2.如果学员存在则进行修改,否则提示学员不存在
            for i in student_list:
                if modify_name == i.name:
                    i.name = name2.get()
                    i.gender = nn2.get()
                    i.tel = tel2.get()
                    break
            else:
                x = tk.StringVar()
                x.set("查无此人")
                l = tk.Label(windows, textvariable=x, bg="pink", font=("Arial", 12), width=20, height=1)
                l.place(x=325, y=300, anchor=NW)
        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        usename2 = tk.Entry(windows, show="")
        usename2.place(x=355, y=50, anchor=NW)
        name2 = tk.Entry(windows, show="")
        name2.place(x=355, y=100, anchor=NW)
        nn2 = tk.Entry(windows, show="")
        nn2.place(x=355, y=150, anchor=NW)
        tel2 = tk.Entry(windows, show="")
        tel2.place(x=355, y=200, anchor=NW)
        usename1 = tk.Label(windows, text='修改学生姓名')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='姓名')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='性别')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='手机号码')
        tel1.place(x=270, y=200, anchor=NW)
        BBB = tk.Button(windows, text="修改",command=modify_student)
        BBB.place(x=400, y=250, anchor=NW)
    def findmame():
        def search_student():
            # 1. ⽤户输⼊⽬标学员姓名
            search_name = name2.get()
            # 2. 如果⽤户输⼊的⽬标学员存在,则打印学员信息,否则提示学员不存在
            m = tk.StringVar()
            for i in student_list:
                if i.name == search_name:
                    m.set(f'{i.name}  {i.gender}  {i.tel}')
                    break
            else:
                m.set("查无此人")
            l = tk.Label(windows, textvariable=m, bg="pink", font=("Arial", 12), width=20, height=1)
            l.place(x=325, y=300, anchor=NW)

        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        name1 = tk.Label(windows, text='输入学员姓名')
        name1.place(x=270, y=100, anchor=NW)
        name2 = tk.Entry(windows, show="")
        name2.place(x=355, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        BBB = tk.Button(windows, text="查询",command=search_student)
        BBB.place(x=400, y=250, anchor=NW)

    def showname():
        def chaxun():
            l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
            l.place(x=150, y=300, anchor=NW)
            for i in student_list:
                l.insert("insert",f'{i.name}  {i.gender}  {i.tel}')
                l.insert("insert","\n")
        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        BBB = tk.Button(windows, text="查询",command=chaxun)
        BBB.place(x=400, y=250, anchor=NW)


    #保存信息
    def getname():
        def save_student():
            # 1. 打开⽂件
            f = open('student.txt', 'w')
            # 2. ⽂件写⼊学员数据
            # 注意1:⽂件写⼊的数据不能是学员对象的内存地址,需要把学员数据转换成列表字典数据再做存储
            new_list = [i.__dict__ for i in student_list]
            # [{'name': 'aa', 'gender': 'nv', 'tel': '111'}]
            # 注意2:⽂件内数据要求为字符串类型,故需要先转换数据类型为字符串才能⽂件写⼊数据
            f.write(str(new_list))
            # 3. 关闭⽂件
            f.close()
        bai = tk.Label(windows, text='                                                        ')
        bai.place(x=325, y=300, anchor=NW)
        usename1 = tk.Label(windows, text='                                                        ')
        usename1.place(x=270, y=50, anchor=NW)
        name1 = tk.Label(windows, text='                                                        ')
        name1.place(x=270, y=100, anchor=NW)
        nn1 = tk.Label(windows, text='                                                        ')
        nn1.place(x=270, y=150, anchor=NW)
        tel1 = tk.Label(windows, text='                                                        ')
        tel1.place(x=270, y=200, anchor=NW)
        l = tk.Text(windows, font=("Arial", 12), width=55, height=9)
        l.place(x=150, y=300, anchor=NW)
        BBB = tk.Button(windows, text="保存",command=save_student)
        BBB.place(x=400, y=250, anchor=NW)

    def goout():
        windows.destroy()

    b1 = tk.Button(windows, text="添加学员", command=addname)
    b1.place(x=0, y=0, anchor=NW)
    b2 = tk.Button(windows, text="删除学员", command=setname)
    b2.place(x=90, y=0, anchor=NW)
    b3 = tk.Button(windows, text="修改信息", command=changename)
    b3.place(x=180, y=0, anchor=NW)
    b4 = tk.Button(windows, text="查询学员信息", command=findmame)
    b4.place(x=270, y=0, anchor=NW)
    b5 = tk.Button(windows, text="显示所有学员信息", command=showname)
    b5.place(x=380, y=0, anchor=NW)
    b6 = tk.Button(windows, text="保存学员信息", command=getname)
    b6.place(x=520, y=0, anchor=NW)
    b7 = tk.Button(windows, text="退出系统", command=goout)
    b7.place(x=630, y=0, anchor=NW)
    addname()
    windows.mainloop()
text1 = tk.Label(window,text='系统账号')
text1.place(x=270,y=80,anchor=NW)
mima1 = tk.Entry(window,show="")
mima1.place(x=355, y=80, anchor=NW)
text2 = tk.Label(window,text='系统密码')
text2.place(x=270,y=150,anchor=NW)
mima2 = tk.Entry(window,show="*")
mima2.place(x=355, y=150, anchor=NW)

sure = tk.Button(window,text = "登录",command=deng_lu)

sure.place(x=350, y=200, anchor=NW)
end = tk.Button(window,text = "退出",command=cup)   #此处当改
end.place(x=460, y=200, anchor=NW)
window.mainloop()

window.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值