当前位置:   article > 正文

python学生成绩管理系统【完整版】_学生成绩管理系统python_python程序设计黄锐军9.4学生成绩管理系统

python程序设计黄锐军9.4学生成绩管理系统

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
img

正文

students.txt

用于存储数据

main.py
from tkinter import \*
from Login import \*
import tkinter as tk

root = tk.Tk()
root.title('欢迎进入学生成绩管理系统')
LoginPage(root)
root.mainloop()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
Login.py
from tkinter import \*
from tkinter.messagebox import \*
from MenuPage import \*


class LoginPage(object):
    def \_\_init\_\_(self, master=None):
        self.root = master  # 定义内部变量root
        self.root.geometry('%dx%d' % (300, 180))  # 设置窗口大小
        self.username = StringVar()
        self.password = StringVar()
        self.createPage()

    def createPage(self):
        self.page = Frame(self.root)  # 创建Frame
        self.page.pack()
        Label(self.page).grid(row=0, stick=W)
        Label(self.page, text='账户: ').grid(row=1, stick=W, pady=10)
        Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=E)
        Label(self.page, text='密码: ').grid(row=2, stick=W, pady=10)
        Entry(self.page, textvariable=self.password, show='\*').grid(row=2, column=1, stick=E)
        Button(self.page, text='登陆', command=self.loginCheck).grid(row=3, stick=W, pady=10)
        Button(self.page, text='退出', command=self.page.quit).grid(row=3, column=1, stick=E)

    def loginCheck(self):
        name = self.username.get()
        password = self.password.get()
        if name == 'hacker707' and password == 'admin':
            self.page.destroy()
            MenuPage(self.root)
        else:
            showinfo(title='错误', message='账号或密码错误!')

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
db.py
import json


class StudentDB(object):
    def \_\_init\_\_(self):
        self.students = []
        self._load_students_data()

    def insert(self, student):
        self.students.append(student)
        print(self.students)

    def all(self):
        return self.students

    def delete\_by\_name(self, name):  # 删除数据
        for student in self.students:
            if name == student["name"]:
                self.students.remove(student)
                break
        else:
            return False
        return True

    # 查询
    def search\_by\_name(self, name):
        for student in self.students:
            if name == student["name"]:
                return student  # 姓名+成绩
        else:
            return False

    # 修改
    def update(self, stu):  # 修改数据
        name = stu["name"]
        for student in self.students:
            if name == student["name"]:
                student.update(stu)
                return True
        else:
            return False

    # 加载文件
    def \_load\_students\_data(self):
        with open("students.txt", "r", encoding="utf-8") as f:
            text = f.read()
        if text:
            self.students = json.loads(text)

    # 保存数据
    def save\_data(self):
        with open("students.txt", 'w', encoding="utf-8") as f:
            text = json.dumps(self.students, ensure_ascii=False)
            f.write(text)


db = StudentDB()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
MenuPage.py
import tkinter as tk
from view import \*


class MenuPage(object):
    def \_\_init\_\_(self, master=None):
        self.root = master
        self.root.geometry('%dx%d' % (600, 400))
        self.create_page()
        self.input_page = InputFrame(self.root)
        self.query_page = QuerryFrame(self.root)
        self.delete_page = DeleteFrame(self.root)
        self.update_page = UpdateFrame(self.root)
        self.about_page = AboutFrame(self.root)
        self.input_page.pack()

    def create\_page(self):
        # 创建菜单对象
        menubar = tk.Menu(self.root)
        # add\_command 添加
        menubar.add_command(label="录入", command=self.input_data)  # label
        menubar.add_command(label="查询", command=self.query_data)  # label
        menubar.add_command(label="删除", command=self.delete_data)  # label
        menubar.add_command(label="修改", command=self.update_data)  # label
        menubar.add_command(label="关于", command=self.about_data)  # label
        # 设置菜单栏
        self.root.config(menu=menubar)

    # 切换界面
    def input\_data(self):
        self.input_page.pack()
        self.update_page.pack_forget()
        self.delete_page.pack_forget()
        self.about_page.pack_forget()
        self.query_page.pack_forget()

    def query\_data(self):
        self.input_page.pack_forget()
        self.query_page.pack()
        self.update_page.pack_forget()
        self.delete_page.pack_forget()
        self.about_page.pack_forget()

    def update\_data(self):
        self.input_page.pack_forget()
        self.update_page.pack()
        self.delete_page.pack_forget()
        self.about_page.pack_forget()
        self.query_page.pack_forget()

    def delete\_data(self):
        self.input_page.pack_forget()
        self.update_page.pack_forget()
        self.delete_page.pack()
        self.about_page.pack_forget()
        self.query_page.pack_forget()

    def about\_data(self):
        self.input_page.pack_forget()
        self.update_page.pack_forget()
        self.delete_page.pack_forget()
        self.about_page.pack()
        self.query_page.pack_forget()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
view.py
import tkinter as tk
from db import db
from tkinter import ttk


# 录入类
class InputFrame(tk.Frame):
    def \_\_init\_\_(self, master=None):
        super().__init__(master)
        self.root = master
        self.name = tk.StringVar()
        self.math = tk.StringVar()
        self.chinese = tk.StringVar()
        self.english = tk.StringVar()
        self.status = tk.StringVar()
        self.create_page()

    def create\_page(self):
        tk.Label(self).grid(row=0, stick=tk.W, pady=10)
        tk.Label(self, text="姓名:").grid(row=1, stick=tk.W, pady=10)
        # 单行文本框 entry,textvariable绑定变量
        tk.Entry(self, textvariable=self.name).grid(row=1, column=1, stick=tk.E)

        tk.Label(self, text="数学:").grid(row=2, stick=tk.W, pady=10)
        # 单行文本框 entry,textvariable绑定变量
        tk.Entry(self, textvariable=self.math).grid(row=2, column=1, stick=tk.E)

        tk.Label(self, text="语文:").grid(row=3, stick=tk.W, pady=10)
        # 单行文本框 entry,textvariable绑定变量
        tk.Entry(self, textvariable=self.chinese).grid(row=3, column=1, stick=tk.E)

        tk.Label(self, text="英语:").grid(row=4, stick=tk.W, pady=10)
        # 单行文本框 entry,textvariable绑定变量
        tk.Entry(self, textvariable=self.english).grid(row=4, column=1, stick=tk.E)

        tk.Button(self, text="录入", command=self.recode_student).grid(row=5, column=1, stick=tk.E, pady=10)
        tk.Label(self, textvariable=self.status).grid(row=6, column=1, stick=tk.E, pady=10)

    # 录入成绩
    def recode\_student(self):
        student = {
            "name": self.name.get(),
            "math": self.math.get(),
            "chinese": self.chinese.get(),
            "english": self.english.get(),
        }  # 一个学生的成绩
        db.insert(student)
        # get()得到值
        # set()设置值
        self.status.set("插入数据成功!")
        self._clear_data()
        db.save_data()

    # 清空文本数据
    def \_clear\_data(self):
        self.name.set("")
        self.math.set("")
        self.chinese.set("")
        self.english.set("")


# 查询类
class QuerryFrame(tk.Frame):
    def \_\_init\_\_(self, master=None):
        super().__init__(master)
        self.root = master
        self.create_page()

    # 创建查询界面
    def create\_page(self):
        self.create_tree_view()
        self.show_data_frame()
        # grid()
        tk.Button(self, text="刷新数据", command=self.show_data_frame).pack(anchor=tk.E, pady=5)

    # Treeview
    def create\_tree\_view(self):
        # 表头
        columns = ("name", "chinese", "math", "english")
        self.tree_view = ttk.Treeview(self, show='headings', columns=columns)
        self.tree_view.column("name", width=80, anchor='center')
        self.tree_view.column("chinese", width=80, anchor='center')
        self.tree_view.column("math", width=80, anchor='center')
        self.tree_view.column("english", width=80, anchor='center')
        self.tree_view.heading("name", text='姓名')
        self.tree_view.heading("chinese", text='语文')
        self.tree_view.heading("math", text='数学')
        self.tree_view.heading("english", text='英语')
        self.tree_view.pack()

    # 显示数据
    def show\_data\_frame(self):
        # 删除原节点 map(int,值)
文末有福利领取哦~
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/769051
推荐阅读
相关标签