首页 > 其他分享 >6.13

6.13

时间:2024-06-16 21:56:05浏览次数:13  
标签:6.13 self column tk entry root row

python错题管理系统

import tkinter as tk
from tkinter import ttk

import pymysql


class WrongQuestionManagementSystem:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("错题本信息管理系统")
        self.create_main_page()
        self.c = None

    def create_main_page(self):

        self.root.title("错题管理系统")

        title_label = tk.Label(self.root, text="错题管理系统", width=100, height=2)
        title_label.grid(row=0, column=0, columnspan=2)

        button1 = tk.Button(self.root, text="查询错题", command=self.create_page1, width=50, height=2)
        button1.grid(row=1, column=0)

        button2 = tk.Button(self.root, text="添加错题", command=self.create_page2, width=50, height=2)
        button2.grid(row=1, column=1)

        button3 = tk.Button(self.root, text="修改错题", command=self.create_page3, width=50, height=2)
        button3.grid(row=2, column=0)

        button4 = tk.Button(self.root, text="删除错题", command=self.create_page4, width=50, height=2)
        button4.grid(row=2, column=1)

        button5 = tk.Button(self.root, text="错题导出", command=self.create_page5, width=100, height=2)
        button5.grid(row=3, column=0, columnspan=2)

    def create_page1(self):
        # 创建新窗口
        new_window = tk.Tk()
        new_window.title("错题查询")

        # 连接数据库
        db_config = {
            'host': 'localhost',
            'user': 'root',
            'password': '246800',
            'database': 'db1'
        }

        db = pymysql.connect(**db_config)
        cursor = db.cursor()

        # 执行数据库查询
        cursor.execute(
            "select question, error_info, analysis, experience, source, reason, difficulty, type, knowledge FROM wrong_questions;")
        data = cursor.fetchall()

        search_label = tk.Label(new_window, text="输入题目:")
        search_label.pack()
        search_entry = tk.Entry(new_window)
        search_entry.pack()

        # 创建Treeview表格
        tree = ttk.Treeview(new_window)
        tree['columns'] = tuple(i[0] for i in cursor.description)
        tree.heading("#0", text="序号")

        for col, col_chinese in zip(tree['columns'],
                                    ["题目", "错误信息:", "答案分析:", "心得体会:", "错题来源:", "难易程度:",
                                     "题目类型:", "知识点:"]):
            tree.heading(col, text=col_chinese)
            tree.column(col, anchor=tk.CENTER)

        tree.column("#0", anchor=tk.CENTER)

        def search():
            tree.delete(*tree.get_children())
            query = search_entry.get().strip()
            if query:
                for row in data:
                    if query in row:
                        tree.insert('', 'end', values=row)
            else:
                for idx, row in enumerate(data, 1):
                    tree.insert('', 'end', text=idx, values=row)

        search_button = tk.Button(new_window, text="搜索", command=search)
        search_button.pack()

        # 返回按钮
        back_button = tk.Button(new_window, text="返回主页", command=new_window.destroy)
        back_button.pack()

        for idx, row in enumerate(data, 1):
            tree.insert('', 'end', text=idx, values=row)

        tree.pack()

        # 关闭数据库连接
        db.close()

        new_window.mainloop()



    def create_page2(self):
        # Create content for page 2
        # Create content for page 2
        self.root.destroy()
        self.root = tk.Tk()
        self.root.title("错题添加")

        tk.Label(self.root, text="题目:",width=40,height=1).grid(row=0, column=0)
        self.question_entry = tk.Entry(self.root)
        self.question_entry.grid(row=0, column=1)

        tk.Label(self.root, text="错误信息:",width=40,height=1).grid(row=1, column=0)
        self.error_entry = tk.Entry(self.root)
        self.error_entry.grid(row=1, column=1)

        tk.Label(self.root, text="答案分析:",width=20,height=1).grid(row=2, column=0)
        self.analysis_entry = tk.Entry(self.root)
        self.analysis_entry.grid(row=2, column=1)

        tk.Label(self.root, text="心得体会:",width=20,height=1).grid(row=3, column=0)
        self.experience_entry = tk.Entry(self.root)
        self.experience_entry.grid(row=3, column=1)

        tk.Label(self.root, text="错题来源:",width=20,height=1).grid(row=4, column=0)
        self.source_entry = tk.Entry(self.root)
        self.source_entry.grid(row=4, column=1)

        tk.Label(self.root, text="错题原因:").grid(row=5, column=0)
        self.reason_entry = tk.Entry(self.root)
        self.reason_entry.grid(row=5, column=1)

        tk.Label(self.root, text="难易程度:",width=20,height=1).grid(row=6, column=0)
        self.difficulty_entry = tk.Entry(self.root)
        self.difficulty_entry.grid(row=6, column=1)

        tk.Label(self.root, text="题目类型:",width=20,height=1).grid(row=7, column=0)
        self.type_entry = tk.Entry(self.root)
        self.type_entry.grid(row=7, column=1)

        tk.Label(self.root, text="知识点:",width=20,height=1).grid(row=8, column=0)
        self.knowledge_entry = tk.Entry(self.root)
        self.knowledge_entry.grid(row=8, column=1)

        tk.Button(self.root, text="录入", command=self.add_wrong_question,width=80,height=1).grid(row=9, column=0, columnspan=2, pady=10)
        # 添加功能
        back_button = tk.Button(self.root, text="返回主页面", command=self.create_main_page)
        back_button.grid(row=10, column=0, columnspan=2, pady=10)


    def add_wrong_question(self):
        question = self.question_entry.get()
        error = self.error_entry.get()
        analysis = self.analysis_entry.get()
        experience = self.experience_entry.get()
        source = self.source_entry.get()
        reason = self.reason_entry.get()
        difficulty = self.difficulty_entry.get()
        qtype = self.type_entry.get()
        knowledge = self.knowledge_entry.get()

        # 连接数据库
        db_config = {
                'host': 'localhost',
                'user': 'root',
                'password': '246800',
                'database': 'db1'
        }

        db = pymysql.connect(**db_config)
        cursor = db.cursor()

        # 插入数据
        sql = "INSERT INTO wrong_questions (question, error_info, analysis, experience, source, reason, difficulty, type, knowledge) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
        values = (question, error, analysis, experience, source, reason, difficulty, qtype, knowledge)
        cursor.execute(sql, values)

        # 提交更改
        db.commit()

        # 关闭数据库连接
        db.close()

        # 清空Entry部件
        self.question_entry.delete(0, 'end')
        self.error_entry.delete(0, 'end')
        self.analysis_entry.delete(0, 'end')
        self.experience_entry.delete(0, 'end')
        self.source_entry.delete(0, 'end')
        self.reason_entry.delete(0, 'end')
        self.difficulty_entry.delete(0, 'end')
        self.type_entry.delete(0, 'end')
        self.knowledge_entry.delete(0, 'end')

        print("题目添加成功!")

    def create_page3(self):
        # Create content for page 2
        self.root.destroy()
        self.root = tk.Tk()
        self.root.title("错题修改")

        tk.Label(self.root, text="题目:", width=40, height=1).grid(row=0, column=0)
        self.search_entry = tk.Entry(self.root)
        self.search_entry.grid(row=0, column=1)

        tk.Button(self.root, text="搜索", command=self.search_wrong_question, width=20, height=1).grid(row=0, column=2)

        back_button = tk.Button(self.root, text="返回主页面", command=self.create_main_page)
        back_button.grid(row=10, column=0, columnspan=2, pady=10)





    def search_wrong_question(self):
        question_to_search = self.search_entry.get()

        # 连接数据库
        db_config = {
            'host': 'localhost',
            'user': 'root',
            'password': '246800',
            'database': 'db1'
        }

        db = pymysql.connect(**db_config)
        cursor = db.cursor()

        # 查询数据
        sql = "select question, error_info, analysis, experience, source, reason, difficulty, type, knowledge FROM wrong_questions WHERE question = %s"
        cursor.execute(sql, (question_to_search,))
        result = cursor.fetchone()

        db.close()

        if result:
            self.create_modify_form(result)
        else:
            print("题目不存在,请重新输入!")

    def modify_wrong_question(self):
        new_question = self.question_entry.get()
        new_error = self.error_entry.get()
        new_analysis = self.analysis_entry.get()
        new_experience = self.experience_entry.get()
        new_source = self.source_entry.get()
        new_reason = self.reason_entry.get()
        new_difficulty = self.difficulty_entry.get()
        new_type = self.type_entry.get()
        new_knowledge = self.knowledge_entry.get()

        db_config = {
            'host': 'localhost',
            'user': 'root',
            'password': '246800',
            'database': 'db1'
        }

        db = pymysql.connect(**db_config)
        cursor = db.cursor()

        sql = "UPDATE wrong_questions SET question = %s, error_info = %s, analysis = %s, experience = %s, source = %s, reason = %s, difficulty = %s, type = %s, knowledge = %s WHERE id = %s"
        # Assuming the ID of the question is 1
        cursor.execute(sql, (
        new_question, new_error, new_analysis, new_experience, new_source, new_reason, new_difficulty, new_type,
        new_knowledge, 1))
        db.commit()

        tk.Label(self.root, text="题目已修改").grid(row=10, column=0, columnspan=2)

    def create_modify_form(self, question_details):
        self.root.destroy()
        self.root = tk.Tk()
        self.root.title("错题修改")



        tk.Label(self.root, text="题目:", width=40, height=1).grid(row=0, column=0)
        self.question_entry = tk.Entry(self.root)
        self.question_entry.grid(row=0, column=1)
        self.question_entry.insert(0, question_details[0])

        tk.Label(self.root, text="错误信息:", width=40, height=1).grid(row=1, column=0)
        self.error_entry = tk.Entry(self.root)
        self.error_entry.grid(row=1, column=1)
        self.error_entry.insert(0, question_details[1])

        tk.Label(self.root, text="答案分析:", width=20, height=1).grid(row=2, column=0)
        self.analysis_entry = tk.Entry(self.root)
        self.analysis_entry.grid(row=2, column=1)
        self.analysis_entry.insert(0, question_details[2])

        tk.Label(self.root, text="心得体会:", width=20, height=1).grid(row=3, column=0)
        self.experience_entry = tk.Entry(self.root)
        self.experience_entry.grid(row=3, column=1)
        self.experience_entry.insert(0, question_details[3])

        tk.Label(self.root, text="错题来源:", width=20, height=1).grid(row=4, column=0)
        self.source_entry = tk.Entry(self.root)
        self.source_entry.grid(row=4, column=1)
        self.source_entry.insert(0, question_details[4])

        tk.Label(self.root, text="错题原因:").grid(row=5, column=0)
        self.reason_entry = tk.Entry(self.root)
        self.reason_entry.grid(row=5, column=1)
        self.reason_entry.insert(0, question_details[5])

        tk.Label(self.root, text="难易程度:", width=20, height=1).grid(row=6, column=0)
        self.difficulty_entry = tk.Entry(self.root)
        self.difficulty_entry.grid(row=6, column=1)
        self.difficulty_entry.insert(0, question_details[6])

        tk.Label(self.root, text="题目类型:", width=20, height=1).grid(row=7, column=0)
        self.type_entry = tk.Entry(self.root)
        self.type_entry.grid(row=7, column=1)
        self.type_entry.insert(0, question_details[7])

        tk.Label(self.root, text="知识点:", width=20, height=1).grid(row=8, column=0)
        self.knowledge_entry = tk.Entry(self.root)
        self.knowledge_entry.grid(row=8, column=1)
        self.knowledge_entry.insert(0, question_details[8])

        tk.Button(self.root, text="修改", command=self.modify_wrong_question, width=80, height=1).grid(row=9, column=0,
                                                                                                       columnspan=2,
                                                                                                       pady=10)


    def create_page4(self):
        self.root.destroy()
        self.root = tk.Tk()
        self.root.title("错题删除")




        def search_question():
            question = self.search_entry.get()

            db_config = {
                'host': 'localhost',
                'user': 'root',
                'password': '246800',
                'database': 'db1'
            }

            db = pymysql.connect(**db_config)
            cursor = db.cursor()

            cursor.execute("SELECT * FROM wrong_questions WHERE question=%s", (question,))
            data = cursor.fetchall()

            if data:
                result_label = tk.Label(self.root, text="找到题目:")
                result_label.pack()
                for row in data:
                    tk.Label(self.root, text=row).pack()
                delete_button = tk.Button(self.root, text="删除题目",
                                          command=lambda: delete_question(question, cursor, db))
                delete_button.pack()
            else:
                tk.Label(self.root, text="未找到题目").pack()

        def delete_question(question, cursor, db):
            cursor.execute("DELETE FROM wrong_questions WHERE question=%s", (question,))
            db.commit()
            tk.Label(self.root, text="题目已删除").pack()

        # 创建搜索框和按钮
        # 创建搜索框和按钮
        tk.Label(self.root, text="输入题目:").pack()
        self.search_entry = tk.Entry(self.root)
        self.search_entry.pack()
        tk.Button(self.root, text="搜索", command=search_question).pack()

        self.root.mainloop()



    def create_page5(self, mysql=None):
        self.root = tk.Tk()
        self.root.title("错题导出")

        export_button = tk.Button(self.root, text="导出题目", command=self.export_questions)
        export_button.pack()

        self.root.mainloop()

    def export_questions(self):
        db_config = {
            'host': 'localhost',
            'user': 'root',
            'password': '246800',
            'database': 'db1'
        }

        db = pymysql.connect(**db_config)
        cursor = db.cursor()

        cursor.execute("SELECT question FROM wrong_questions")
        data = cursor.fetchall()

        with open("exported_questions.txt", "w") as file:
            for row in data:
                file.write(row[0] + "\n")

        cursor.close()

        tk.Label(self.root, text="题目已成功导出到 exported_questions.txt 文件").pack()



    def run(self):
        self.root.mainloop()


if __name__ == "__main__":

    app = WrongQuestionManagementSystem()
    app.run()

 

标签:6.13,self,column,tk,entry,root,row
From: https://www.cnblogs.com/Christmas77/p/18251325

相关文章

  • 6.13
    今日学习总结学习时间1.5h代码如下packagecom.app.chapter04;importandroid.content.ComponentName;importandroid.content.Intent;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.View;importandroidx.activity.EdgeToEdge;importandroidx.appco......
  • 6.13安卓开发日记57
    今天完成工程数学作业实验五实验五:MATLAB最优化工具箱的使用一、实验目的通过一个农业生产计划优化安排的实例求解,培养学生解决实际线性规划问题的初步能力;熟悉线性规划的建模过程;掌握Matlab优化工具箱中线性规划函数的调用。通过一个投资组合优化问题的实例求解,培养学生解决......
  • 6.13学习内容
    今天完成了计算机网络的实验三 综合性训练(搭建中小企业园区网)一、实验目的:1.通过对网络设备的连通和对拓扑的分析,加深对常见典型局域网拓扑的理解;2.通过路由建立起网络之间的连接,了解网络路由的设计与配置;3.进一步熟悉交换机、路由器的基本操作命令。二、实验设备:六个PC,两......
  • 6.13-栈与队列
    基础知识首先大家要知道栈和队列是STL(C++标准库)里面的两个数据结构。C++标准库是有多个版本的,要知道我们使用的STL是哪个版本,才能知道对应的栈和队列的实现原理。那么来介绍一下,三个最为普遍的STL版本:HPSTL其他版本的C++STL,一般是以HPSTL为蓝本实现出来的,HPSTL是C++S......
  • 6.13模拟赛题解
    前面是题解,后面是垃圾话。T1P1541[NOIP2010提高组]乌龟棋没脑子直接设\(f_{p,i,j,k,w}\),为走到\(p\),还剩\(1,2,3,4\)牌各\(i,j,k,w\)张,\(9\cdot10^8\),发现到一个点只要三种牌的数量确定,最后一种也确定了,所以直接设\(f_{p,i,j,k}\)表示三种牌的就行,大力DP即可。T......
  • 6.13API接口服务类漏洞探针
    ip地址解析:www.x.x.x.com,对应网站目录为d:/wwwroot/xiaodi/而127.x.x.x,对应网站目录为d:/wwwroot/,可能存在网站备份文件zip,所以ip网址端口都的扫描;协议端弱口令爆破:超级弱口令检查工具;端口服务安全问题(用于无思路时)思路:利用探针对端口探测后,对口令安全、Web漏洞、中间......
  • 2024.6.13
    2024.6.13【痛苦的,热烈的,误解的,无解的,快乐的,解脱的】Thursday五月初八<theme=oi-"gametheory">P4018Roy&October之取石子Roy&October之取石子题目背景Roy和October两人在玩一个取石子的游戏。题目描述游戏规则是这样的:共有\(n\)个石子,两人每次都只能取\(p^......
  • 文献精读_2024.06.13
    Universalandextensiblelanguage-visionmodelsfororgansegmentationandtumordetectionfromabdominalcomputedtomography来源:https://doi.org/10.1016/j.media.2024.103226GitHub仓库:https://github.com/ljwztc/CLIP-Driven-Universal-Model第一眼,仓库上面放......
  • 6.13 个人总结
    在这个学期的学习旅程中,我作为软件工程专业的学生,经历了从理论到实践的全方位锻炼,不仅在专业技能上取得了显著进步,也在团队协作、项目管理和自我认知方面获得了宝贵的经验。以下是对我本学期学习经历的全面总结,包括对上述问题的深入思考。 1.课程计划完成程度回顾我的第一周课......
  • 完美解码 最新版 2023.06.13
    因为完美解码官网的下载链接404了,所以给大家分享一下。完美解码是一款能实现各种流行视频、HDTV播放及编码的全能型影音解码包,自带MediaPlayerClassic、KMPlayer、PotPlayer三款流行播放器,支持简、英语言平台下安装,能播放AVI、VCD、DVD、MPG、MP4、RMVB、TS、TP、EVO、M2......