首页 > 其他分享 >5.31安卓开发日记48

5.31安卓开发日记48

时间:2024-06-15 23:43:06浏览次数:11  
标签:val 48 安卓 tk pady padx pack self 5.31

Ⅶ、代码

main.py

import tkinter as tk
from tkinter import ttk, messagebox
from PIL import Image, ImageTk
import mysql.connector
import select


# 数据库连接函数
def create_connection():
return mysql.connector.connect(
host='localhost',
user='root', # 使用你的数据库用户名
password='123456789', # 使用你的数据库密码
database='MistakeDB'
)


# 插入数据到数据库的函数
def insert_mistake(conn, question, error_info, answer_analysis, thoughts, source, reason, difficulty, question_type,
knowledge_point):
cursor = conn.cursor()
sql = (
"INSERT INTO mistakes (question, error_info, answer_analysis, thoughts, source, reason, difficulty, question_type, knowledge_point) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)")
val = (question, error_info, answer_analysis, thoughts, source, reason, difficulty, question_type, knowledge_point)
cursor.execute(sql, val)
conn.commit()
cursor.close()


# 主界面类
class MainInterface(tk.Tk):
def __init__(self):
super().__init__()
self.title("错题本信息管理系统")
self.state('zoomed')
self.setup_background()
self.create_widgets()

# 初始化输入页面Frame,但不显示
self.input_page_frame = None

def setup_background(self):
"""设置背景图片"""
self.background_image = Image.open("background.jpg") # 确保图片存在并正确命名
self.background_image = self.background_image.resize((self.winfo_screenwidth(), self.winfo_screenheight()),
resample=Image.Resampling.LANCZOS)
self.background_tk = ImageTk.PhotoImage(self.background_image)
background_label = tk.Label(self, image=self.background_tk)
background_label.image = self.background_tk
background_label.place(relwidth=1, relheight=1)

def create_widgets(self):
"""创建主界面控件"""
main_frame = tk.Frame(self, bg="lightgray")
main_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)

title_font = ("Helvetica", 36, "bold")
title_label = tk.Label(main_frame, text="错题本信息管理系统", font=title_font, bg="lightgray", pady=20)
title_label.pack(pady=20)

buttons_frame = tk.Frame(main_frame)
buttons_frame.pack(expand=True, pady=(0, 20))

add_button = tk.Button(buttons_frame, text="错题录入", command=self.show_input_page, font=("Helvetica", 18),
width=20)
add_button.pack(fill=tk.X, pady=50)

query_button = tk.Button(buttons_frame, text="查询显示", command=self.open_query_page, font=("Helvetica", 18),
width=20)
query_button.pack(fill=tk.X, pady=50)

def show_input_page(self):
"""显示错题录入页面"""
if self.input_page_frame is None:
self.input_page_frame = InputPage(self)
self.input_page_frame.pack(fill=tk.BOTH, expand=True)
self.hide_main_widgets()

def hide_input_page(self):
"""隐藏错题录入页面"""
if self.input_page_frame:
self.input_page_frame.pack_forget()
self.show_main_widgets()

def hide_main_widgets(self):
"""隐藏主界面控件"""
for widget in self.winfo_children():
if widget != self.input_page_frame:
widget.pack_forget()

def show_main_widgets(self):
"""显示主界面控件"""
main_frame = self.winfo_children()[1] # Assuming main frame is the second child after background label
main_frame.pack(fill=tk.BOTH, expand=True)

def open_query_page(self):
"""打开查询显示页面的占位函数"""
print("打开查询显示页面")
# 这里可以添加打开查询显示页面的代码
select.main()


# 错题录入页面类
# 错题录入页面类
class InputPage(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.configure(bg="lightgray")
self.create_input_widgets()

def create_input_widgets(self):
"""创建录入页面控件"""
padx_val = 10
pady_val = 5

# 题目输入框
tk.Label(self, text="题目:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_question = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_question.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 错误信息输入框
tk.Label(self, text="错误信息:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_error_info = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_error_info.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 答案分析输入框
tk.Label(self, text="答案分析:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_answer_analysis = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_answer_analysis.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 心得体会输入框
tk.Label(self, text="心得体会:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_thoughts = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_thoughts.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 来源输入框
tk.Label(self, text="来源:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_source = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_source.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 原因输入框
tk.Label(self, text="原因:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_reason = tk.Text(self, width=50, height=2, wrap=tk.WORD)
self.entry_reason.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 难易程度下拉菜单
tk.Label(self, text="难易程度:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
difficulty_options = ["简单", "中等", "困难"]
self.difficulty_var = tk.StringVar()
self.difficulty_menu = ttk.Combobox(self, textvariable=self.difficulty_var, values=difficulty_options)
self.difficulty_menu.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 题目类型下拉菜单
tk.Label(self, text="题目类型:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
type_options = ["选择题", "填空题", "解答题"]
self.type_var = tk.StringVar()
self.type_menu = ttk.Combobox(self, textvariable=self.type_var, values=type_options)
self.type_menu.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 知识点输入框
tk.Label(self, text="知识点:", bg="lightgray").pack(anchor=tk.W, padx=padx_val, pady=pady_val)
self.entry_knowledge_point = tk.Text(self, width=50, height=3, wrap=tk.WORD)
self.entry_knowledge_point.pack(anchor=tk.W, padx=padx_val, pady=pady_val)

# 保存按钮
tk.Button(self, text="保存并返回", command=self.save_and_close).pack(side=tk.BOTTOM, pady=20)
# 保存按钮
tk.Button(self, text="返回", command=self.return_to_main).pack(side=tk.BOTTOM, pady=20)

def return_to_main(self):
"""返回到主界面"""
self.master.hide_input_page() # 隐藏错题录入页面
self.master.show_main_widgets() # 显示主界面控件

def save_and_close(self):
"""保存错题信息并返回主界面"""
# 获取所有输入控件的数据
question = self.entry_question.get("1.0", 'end-1c')
error_info = self.entry_error_info.get("1.0", 'end-1c')
answer_analysis = self.entry_answer_analysis.get("1.0", 'end-1c')
thoughts = self.entry_thoughts.get("1.0", 'end-1c')
source = self.entry_source.get("1.0", 'end-1c')
reason = self.entry_reason.get("1.0", 'end-1c')
difficulty = self.difficulty_var.get()
question_type = self.type_var.get()
knowledge_point = self.entry_knowledge_point.get("1.0", 'end-1c')

try:
conn = create_connection()
if conn.is_connected():
insert_mistake(conn, question, error_info, answer_analysis, thoughts, source, reason, difficulty,
question_type, knowledge_point)
messagebox.showinfo("成功", "错题信息已保存!")
else:
messagebox.showerror("错误", "无法连接到数据库!")
except mysql.connector.Error as err:
messagebox.showerror("数据库错误", f"发生错误: {err}")
finally:
if conn and conn.is_connected():
conn.close()
self.entry_question.delete("1.0", 'end')
self.entry_error_info.delete("1.0", 'end')
self.entry_answer_analysis.delete("1.0", 'end')
self.entry_thoughts.delete("1.0", 'end')
self.entry_source.delete("1.0", 'end')
self.entry_reason.delete("1.0", 'end')
self.entry_knowledge_point.delete("1.0", 'end')

self.master.hide_input_page()

# 运行应用
if __name__ == "__main__":
app = MainInterface()
app.mainloop()

标签:val,48,安卓,tk,pady,padx,pack,self,5.31
From: https://www.cnblogs.com/lml66/p/18250036

相关文章

  • 5.11安卓开发日记32
    今天上数据库原理,实验二是给出数据后对数据进行多方面的查询。4、在数据库test1中进行下列查询操作,将查询语句与结果写入实验报告。(1)查询所有供应商情况,先按城市升序排列,城市相同按供应商名称降序排列。select*fromsorderbycityasc,snamedesc;(2)查询所有零件情况,先按......
  • 5.9安卓开发日记31
    今天继续进行python实验,学习到了python与java在类的定义、继承、多态等方面的异同。Python和Java都是面向对象的编程语言,它们在类的定义、继承、多态等方面有相似之处,但也存在一些显著差异。下面通过具体例子来比较这两种语言在面向对象编程上的异同,并总结Python面向对象编程的一......
  • 5.8安卓开发日记30
    今天学习python实验,本次的实验为python中的实体类,随着实验的进行,让我发现它的实体类和cc++java的实体类大同小异,只需要记住相关写法,着重记一点区别,就能很快适应python实体类的书写。【题目描述】定义一个人员类People,其属性有:姓名、性别、年龄;基于People实现学生类Student,添加......
  • 安卓签名文件打包错误 Invalid keystore format
    1.错误java.io.IOException:Invalidkeystoreformat...2.解决方案        方案1:                找到debug.keystore并删除                 路径 User\用户名\android\debug.keystore                 ......
  • DreamJudge-1248-整数奇偶排序
    1.题目描述TimeLimit:1000msMemoryLimit:256mb输入10个整数,彼此以空格分隔。重新排序以后输出(也按空格分隔),要求:1.先输出其中的奇数,并按从大到小排列;2.然后输出其中的偶数,并按从小到大排列。输入输出格式输入描述:任意排序的10个整数(0~100),彼此以空格分隔。输......
  • 《pvz植物大战僵尸杂交版》V2.0.88整合包火爆全网,支持安卓、ios、电脑等!
    今天来给大家安利一款让人欲罢不能的游戏——《植物大战僵尸·杂交版》2.0.88版。这可不是普通的植物大战僵尸,它可是席卷了B站,火爆全网的存在!先说说这个版本,它可是网络上现存最全的植物大战僵尸杂交版整合包。里面不仅有修改工具,还有超强通关存档和高清工具,简直是玩家的福音。......
  • 5.31
    今天完成数据库原理实验四1、开始→程序→MicrosoftSQLServer→SQLServerManagementStdio。2、在“连接到服务器”对话框中,选择“Windows身份验证”,点击“连接”,进入SQLServerManagementStdio操作界面。3、创建students数据库。利用如下sql语句在students......
  • 安卓录屏怎么录?让你成为录屏达人!
    “安卓手机录屏怎么操作?我近期刚刚从苹果手机转到了安卓手机,发现很多功能操作都有所不同。尤其是现在我需要用到录屏功能,但在我的新安卓手机上找不到这个选项。请问有谁知道安卓手机录屏的具体步骤吗?”随着移动互联网的快速发展,手机已经成为我们日常生活中不可或缺的一部分。......
  • 安卓应用开发——Android Studio中通过id进行约束布局
    在Android开发中,布局通常使用XML文件来描述,而约束(如相对位置、大小等)可以通过多种方式实现,但直接使用ID进行约束并不直接对应于Android的传统布局系统(如LinearLayout、RelativeLayout等)。然而,从AndroidStudio3.0开始,引入了ConstraintLayout,它允许你通过ID来定义视图之间的约......
  • PIC18 bootloader之RS485 bootloader
                   了解更多关于bootloader的C语言实现,请加我Q扣:1273623966(验证信息请填bootloader),欢迎咨询或定制bootloader(在线升级程序)。    不知道为什么,现在工业控制领域也向汽车领域学习,产品需要带bootloader,产品出货后也要可......