gyt200300 6 months ago
parent a732fc342c
commit 13d4b96f2d

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/extracted_data.csv" charset="GBK" />
</component>
</project>

@ -1,33 +0,0 @@
# -*- coding: gbk -*-
import pymysql
import pandas as pd
# -*- coding: <encoding name> -*-
db_config = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '21412030117',
'database': 'word',
'charset': 'utf8mb4',
}
try:
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
extracted='words.csv'
data_to_insert= pd.read_csv(extracted)
for item in data_to_insert:
xuhao, neirong = item
insert_sql = "INSERT INTO word (xuhao, neirong) VALUES (%s, %s)"
cursor.execute(insert_sql, (xuhao, neirong))
connection.commit()
print("数据插入成功!")
except Exception as e:
print(f"数据插入失败,错误信息:{e}")

@ -1,39 +0,0 @@
import re
import csv
from bs4 import BeautifulSoup
import requests
url = 'https://zhuanlan.zhihu.com/p/105570623'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 初始化数据列表,用于存放提取的信息
data = []
# 假设我们要提取页面上的所有段落文本中数字加句号后面的内容
paragraphs = soup.find_all('p')
for paragraph in paragraphs:
text = paragraph.get_text()
# 使用正则表达式匹配数字加句号后面的内容
matches = re.findall(r'\d+\.\s*(.*)', text)
for match in matches:
# 将匹配到的内容添加到data列表中这里假设序号是连续的从1开始递增
data.append([len(data)+1, match.strip()])
# 定义CSV文件的名称
filename = 'extracted_data.csv'
# 写入CSV文件
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
csvwriter = csv.writer(csvfile)
# 写入表头
csvwriter.writerow(['序号', '内容',''])
# 写入数据
for row in data:
# 注意,原问题没有明确"单词"来源,这里假设每条数据只有序号和内容两列
csvwriter.writerow(row)
print(f"数据已成功写入{filename}")

@ -1,39 +0,0 @@
import tkinter as tk
from tkinter import messagebox
import csv
class WordApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("单词学习")
self.current_word_index = 0
self.words = self._read_words_from_csv() # 确保方法名正确且定义在类内部
self.word_label = tk.Label(self, text="", font=("Helvetica", 20))
self.word_label.pack(pady=20)
self.create_buttons()
def _read_words_from_csv(self): # 假设这个方法已被定义在这里
words = []
with open('words.csv', mode='r', encoding='utf-8') as file:
reader = csv.reader(file)
for row in reader:
words.append(row[1]) # 假设单词在CSV的第一列
return words
def create_buttons(self):
self.know_button = tk.Button(self, text="认识", command=self.show_next_word, width=10)
self.not_know_button = tk.Button(self, text="不认识", command=self.show_next_word, width=10)
self.know_button.pack(side=tk.LEFT, padx=10, pady=10)
self.not_know_button.pack(side=tk.RIGHT, padx=10, pady=10)
def show_next_word(self):
if self.current_word_index < len(self.words):
self.word_label.config(text=self.words[self.current_word_index])
self.current_word_index += 1
else:
messagebox.showinfo("结束", "所有单词已学习完毕!")
self.destroy()
if __name__ == "__main__":
app = WordApp()
app.mainloop()

Binary file not shown.

@ -1,71 +0,0 @@
序号,内容
1,abandon vt.丢弃;放弃,抛弃
2,ability n.能力;能耐,本领
3,abnormal a.不正常的;变态的
4,aboard ad.在船(车)上;上船
5,abroad ad.(在)国外;到处
6,absence n.缺席,不在场;缺乏
7,absent a.不在场的;缺乏的
8,abstract a.抽象的 n.摘要
9,abundant a.丰富的;大量的
10,abuse vt.滥用;虐待 n.滥用
11,access n.接近;通道,入口
12,accompany vt.陪伴,陪同;伴随
13,accomplish vt.达到(目的);完成
14,account n.记述;解释;帐目
15,accuse vt.指责;归咎于
16,accustom vt.使习惯
17,accustomed a.惯常的;习惯的
18,achieve vt.完成,实现;达到
19,achievement n.完成;成就,成绩
20,acquaintance n.认识;了解;熟人
21,act vi.行动;见效 n.行为
22,action n.行动;作用;功能
23,active a.活跃的;积极的
24,activity n.活动;活力;行动
25,actress n.女演员
26,actually ad.实际上;竟然
27,acute a.尖的,锐的;敏锐的
28,add vt.添加,附加,掺加
29,addition n.加,加法;附加物
30,additional a.附加的,追加的
31,address n.地址;演说;谈吐
32,adjust vt.调整,调节;校正
33,administration n.管理;管理部门
34,admire vt.钦佩,羡慕,赞赏
35,admission n.允许进入;承认
36,admit vt.承认;准许…进入
37,advance vi.前进;提高 n.进展
38,advanced a.先进的;高级的
39,advantage n.优点,优势;好处
40,adventure n.冒险;惊险活动
41,adult
42,advertisement n.广告;登广告
43,advisable n.明智的;可取的
44,advise vt.劝告;建议;通知
45,affect vt.影响;感动
46,affection n.慈爱,爱;爱慕
47,afford vt.担负得起…;提供
48,aggressive a.侵略的;好斗的
49,agony n.极度痛苦
50,agreement n.协定,协议;同意
51,agriculture n.农业,农艺;农学
52,aid n.帮助,救护;助手
53,airline
54,alphabet n.字母表,字母系统
55,alter vt.改变,变更;改做
56,alternative n.替换物;取舍,抉择
57,although conj.尽管,虽然
58,altitude n.高,高度;高处
59,altogether ad.完全;总而言之
60,amaze vt.使惊奇,使惊愕
61,ambition n.雄心,抱负,野心
62,ambitious
63,ambulance n.救护车;野战医院
64,amplify vt.放大,增强;扩大
65,amuse vt.逗…乐;给…娱乐
66,angel n.天使,神差,安琪儿
67,anger n.怒,愤怒 vt.使发怒
68,angle n.角,角度
69,ankle n.踝,踝节部
70,a
1 序号 内容
2 1 abandon vt.丢弃;放弃,抛弃
3 2 ability n.能力;能耐,本领
4 3 abnormal a.不正常的;变态的
5 4 aboard ad.在船(车)上;上船
6 5 abroad ad.(在)国外;到处
7 6 absence n.缺席,不在场;缺乏
8 7 absent a.不在场的;缺乏的
9 8 abstract a.抽象的 n.摘要
10 9 abundant a.丰富的;大量的
11 10 abuse vt.滥用;虐待 n.滥用
12 11 access n.接近;通道,入口
13 12 accompany vt.陪伴,陪同;伴随
14 13 accomplish vt.达到(目的);完成
15 14 account n.记述;解释;帐目
16 15 accuse vt.指责;归咎于
17 16 accustom vt.使习惯
18 17 accustomed a.惯常的;习惯的
19 18 achieve vt.完成,实现;达到
20 19 achievement n.完成;成就,成绩
21 20 acquaintance n.认识;了解;熟人
22 21 act vi.行动;见效 n.行为
23 22 action n.行动;作用;功能
24 23 active a.活跃的;积极的
25 24 activity n.活动;活力;行动
26 25 actress n.女演员
27 26 actually ad.实际上;竟然
28 27 acute a.尖的,锐的;敏锐的
29 28 add vt.添加,附加,掺加
30 29 addition n.加,加法;附加物
31 30 additional a.附加的,追加的
32 31 address n.地址;演说;谈吐
33 32 adjust vt.调整,调节;校正
34 33 administration n.管理;管理部门
35 34 admire vt.钦佩,羡慕,赞赏
36 35 admission n.允许进入;承认
37 36 admit vt.承认;准许…进入
38 37 advance vi.前进;提高 n.进展
39 38 advanced a.先进的;高级的
40 39 advantage n.优点,优势;好处
41 40 adventure n.冒险;惊险活动
42 41 adult
43 42 advertisement n.广告;登广告
44 43 advisable n.明智的;可取的
45 44 advise vt.劝告;建议;通知
46 45 affect vt.影响;感动
47 46 affection n.慈爱,爱;爱慕
48 47 afford vt.担负得起…;提供
49 48 aggressive a.侵略的;好斗的
50 49 agony n.极度痛苦
51 50 agreement n.协定,协议;同意
52 51 agriculture n.农业,农艺;农学
53 52 aid n.帮助,救护;助手
54 53 airline
55 54 alphabet n.字母表,字母系统
56 55 alter vt.改变,变更;改做
57 56 alternative n.替换物;取舍,抉择
58 57 although conj.尽管,虽然
59 58 altitude n.高,高度;高处
60 59 altogether ad.完全;总而言之
61 60 amaze vt.使惊奇,使惊愕
62 61 ambition n.雄心,抱负,野心
63 62 ambitious
64 63 ambulance n.救护车;野战医院
65 64 amplify vt.放大,增强;扩大
66 65 amuse vt.逗…乐;给…娱乐
67 66 angel n.天使,神差,安琪儿
68 67 anger n.怒,愤怒 vt.使发怒
69 68 angle n.角,角度
70 69 ankle n.踝,踝节部
71 70 a

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (pythonProject)" />
<option name="sdkName" value="Python 3.12 (pythonProject1)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject1)" project-jdk-type="Python SDK" />
</project>

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject1.iml" filepath="$PROJECT_DIR$/.idea/pythonProject1.iml" />
</modules>
</component>
</project>

@ -2,9 +2,9 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12 (pythonProject)" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,35 @@
import pymysql
# 数据库连接参数
db_config = {
'host': 'localhost', # 数据库地址默认localhost
'port': 3306, # 数据库端口默认3306
'user': 'root', # 数据库用户名
'password': '21412030117', # 数据库密码
'database': 'word', # 要连接的数据库名
'charset': 'utf8mb4', # 字符编码推荐使用utf8mb4支持更多字符集
}
# 尝试建立连接
try:
connection = pymysql.connect(**db_config)
print("连接MySQL数据库成功")
# 创建游标
cursor = connection.cursor()
# 执行SQL查询
sql_query = "SELECT * FROM words"
cursor.execute(sql_query)
# 获取查询结果
results = cursor.fetchall()
for row in results:
print(row)
# 关闭游标和连接
cursor.close()
connection.close()
except pymysql.MySQLError as e:
print(f"连接数据库时发生错误: {e}")

@ -0,0 +1,260 @@
import tkinter as tk
from tkinter import messagebox
import random
import pymysql
class LoginPage(tk.Toplevel):
def __init__(self, master=None):
super().__init__(master)
self.title("登录")
self.geometry("200x200")
self.username_var = tk.StringVar()
self.password_var = tk.StringVar()
tk.Label(self, text="用户名:").pack()
tk.Entry(self, textvariable=self.username_var).pack()
tk.Label(self, text="密码:").pack()
tk.Entry(self, show="*", textvariable=self.password_var).pack()
tk.Button(self, text="登录", command=self.login).pack(pady=10)
def login(self):
username = self.username_var.get()
password = self.password_var.get()
if username == "a" and password == "123456":
self.master.destroy() # 关闭主窗口(如果有),这里假设直接关闭自身也行,取决于实际结构
MainApp().mainloop() # 登录成功后实例化MainApp并启动其主循环
else:
messagebox.showerror("错误", "用户名或密码错误!") # 登录失败,保持登录界面打开供用户重试
class MainApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("单词学习")
self.geometry("200x200")
# 创建三个按钮
tk.Button(self, text="学习新单词", command=self.open_window1).pack(fill=tk.X, padx=10, pady=5)
tk.Button(self, text="复习单词", command=self.open_window2).pack(fill=tk.X, padx=10, pady=5)
tk.Button(self, text="易错单词查看", command=self.open_window3).pack(fill=tk.X, padx=10, pady=5)
def open_window1(self):
Window1(self)
def open_window2(self):
Window2(self)
def open_window3(self):
Window3(self)
class Window1(tk.Toplevel):
def __init__(self, master):
super().__init__(master)
self.title("单词学习界面")
# 初始化MySQL数据库连接
self.conn = pymysql.connect(
host="localhost", # MySQL服务器地址
user="root", # 数据库用户名
password="21412030117", # 数据库密码
database="word", # 数据库名
charset='utf8mb4', # 字符编码,根据需要调整
cursorclass=pymysql.cursors.DictCursor # 使用字典游标,方便通过列名访问数据
)
self.cursor = self.conn.cursor()
self.word_frame = tk.Frame(self)
self.word_frame.pack(padx=10, pady=10)
self.next_button = tk.Button(self, text="下一个单词", command=self.show_next_word)
self.next_button.pack(side=tk.RIGHT, padx=5, pady=5)
self.prev_button = tk.Button(self, text="上一个单词") # 实现逻辑待补充
self.prev_button.pack(side=tk.LEFT, padx=5, pady=5)
self.show_next_word() # 初始显示一个单词
def show_next_word(self):
# 查询并获取一个未学习的单词
query = ("SELECT word, meaning FROM words WHERE learned = 0 ORDER BY RAND() LIMIT 1")
self.cursor.execute(query)
word_row = self.cursor.fetchone()
if word_row:
word, meaning = word_row['word'], word_row['meaning'] # 使用字典访问列
self.display_word(word, meaning)
# 标记该单词为已学习
self.mark_word_as_learned(word)
else:
messagebox.showinfo("提示", "所有单词都已学习过!")
def display_word(self, word, meaning):
"""显示单词及其意义"""
for widget in self.word_frame.winfo_children():
widget.destroy()
tk.Label(self.word_frame, text=f"单词: {word}").pack(anchor=tk.W)
tk.Label(self.word_frame, text=f"意义: {meaning}").pack(anchor=tk.W)
def mark_word_as_learned(self, word):
"""将单词标记为已学习"""
update_query = ("UPDATE words SET learned = 1 WHERE word = %s")
self.cursor.execute(update_query, (word,))
self.conn.commit()
class Window2(tk.Toplevel):
def __init__(self, master):
super().__init__(master)
self.title("单词拼写测试")
self.conn = pymysql.connect(
host="localhost",
user="root",
password="21412030117",
database="word",
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
self.cursor = self.conn.cursor()
self.setup_ui()
self.protocol("WM_DELETE_WINDOW", self.on_closing)
self.word_error_count = {} # 新增:存储单词错误次数的字典
def setup_ui(self):
self.word_label = tk.Label(self, text="", font=("Arial", 16))
self.word_label.pack(pady=10)
self.entry_var = tk.StringVar()
self.user_entry = tk.Entry(self, textvariable=self.entry_var, font=("Arial", 14))
self.user_entry.pack(ipady=5, pady=10)
self.result_label = tk.Label(self, text="", fg="black", font=("Arial", 12))
self.result_label.pack(pady=5)
self.next_button = tk.Button(self, text="下一个单词", state=tk.DISABLED, command=self.show_next_word)
self.next_button.pack(pady=10)
self.show_next_word() # 初始化显示一个单词
def show_next_word(self):
self.next_button.config(state=tk.DISABLED) # 禁用按钮防止重复点击
self.cursor.execute("SELECT `word`, `meaning` FROM `words` WHERE `learned` = 1 ORDER BY RAND() LIMIT 1")
word_row = self.cursor.fetchone()
if word_row:
self.current_word = word_row['word']
self.current_meaning = word_row['meaning']
self.word_label.config(text=f"含义:{self.current_meaning}")
self.entry_var.set("") # 清空输入框
self.result_label.config(text="")
self.user_entry.bind("<Return>", lambda event: self.check_spelling()) # 绑定回车键检查拼写
else:
messagebox.showinfo("提示", "没有更多已学习的单词可供测试!")
self.destroy()
def check_spelling(self):
user_input = self.entry_var.get().strip().lower()
if user_input == self.current_word.lower():
self.result_label.config(text="正确!", fg="green")
self.next_button.config(state=tk.NORMAL) # 正确后启用按钮
self.entry_var.set("") # 清空输入框
self.result_label.config(text="")
self.word_error_count[self.current_word] = 0 # 重置错误计数
else:
self.result_label.config(text=f"错误!", fg="red")
self.user_entry.delete(0, tk.END) # 清空输入框并显示正确答案
self.user_entry.insert(0, self.current_word) # 在输入框中显示正确答案
self.user_entry.config(fg="red") # 将输入框文字颜色设为红色
self.user_entry.unbind("<Return>") # 避免在显示答案时响应回车键
self.user_entry.bind("<Button-1>", lambda event: self.clear_and_rebind(event)) # 绑定左键点击事件以清除并重新绑定
# 更新错误计数
if self.current_word in self.word_error_count:
self.word_error_count[self.current_word] += 1
else:
self.word_error_count[self.current_word] = 1
# 达到错误次数限制时更新数据库
if self.word_error_count[self.current_word] > 3:
self.update_easily_mistaken_in_db()
def update_easily_mistaken_in_db(self):
"""更新数据库中单词的easily_mistaken字段为1"""
try:
update_query = (
"UPDATE `words` SET `easily_mistaken` = 1 "
"WHERE `word` = %s AND `easily_mistaken` != 1"
)
self.cursor.execute(update_query, (self.current_word,))
self.conn.commit()
print(f"单词'{self.current_word}'标记为易错单词。")
except Exception as e:
print(f"更新数据库时出错:{e}")
def clear_and_rebind(self, event):
self.user_entry.delete(0, tk.END) # 清空输入框
self.user_entry.config(fg="black") # 重置输入框文字颜色为黑色
self.user_entry.bind("<Return>", lambda event: self.check_spelling()) # 重新绑定回车键事件
def on_closing(self):
self.conn.close()
self.destroy()
class Window3(tk.Toplevel):
def __init__(self, master):
super().__init__(master)
self.title("易错单词复习")
self.conn = pymysql.connect(
host="localhost",
user="root",
password="21412030117",
database="word",
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
self.cursor = self.conn.cursor()
self.setup_ui()
self.show_next_mistaken_word() # 初始化显示一个易错单词
def setup_ui(self):
self.word_label = tk.Label(self, text="", font=("Arial", 16))
self.word_label.pack(pady=10)
self.next_button = tk.Button(self, text="下一个单词", command=self.show_next_mistaken_word)
self.next_button.pack(pady=10)
def show_next_mistaken_word(self):
self.cursor.execute("SELECT `word`, `meaning` FROM `words` WHERE `easily_mistaken` = 1 ORDER BY RAND() LIMIT 1")
word_row = self.cursor.fetchone()
if word_row:
self.current_word = word_row['word']
self.current_meaning = word_row['meaning']
self.word_label.config(text=f"含义:{self.current_meaning}")
else:
messagebox.showinfo("提示", "没有更多易错单词可供复习!")
self.destroy()
def on_closing(self):
self.conn.close()
self.destroy()
def protocol(self, event):
self.on_closing()
# 在创建Window3实例的地方确保调用protocol方法绑定关闭事件
#window3 = Window3(root)
#window3.protocol("WM_DELETE_WINDOW", window3.on_closing)
def start_application():
root = tk.Tk()
root.withdraw() # 隐藏根窗口因为我们直接使用Toplevel作为登录界面
LoginPage(master=root) # 将主窗口作为master传给LoginPage便于后续操作
root.mainloop() # 主循环在此启动,控制整个应用的生命周期
if __name__ == "__main__":
start_application()
Loading…
Cancel
Save