parent
9e7123f63c
commit
e6ce81d9c0
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?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>
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (pythonProject)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12 (pythonProject)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,36 @@
|
||||
# -*- coding: gbk -*-
|
||||
from typing import List
|
||||
|
||||
import mysql
|
||||
import mysql.connector
|
||||
import csv
|
||||
|
||||
db_config = {
|
||||
'host': 'Mysql',
|
||||
'user': 'root',
|
||||
'password': '21412030117',
|
||||
'database': 'words',
|
||||
}
|
||||
|
||||
cnx = mysql.connector.connect(**db_config)
|
||||
cursor = cnx.cursor()
|
||||
|
||||
# 读取CSV
|
||||
with open('extracted_data.csv', mode='r', encoding='utf-8') as file:
|
||||
reader = csv.reader(file)
|
||||
headers = next(reader, None)
|
||||
if headers is not None: # 过表头
|
||||
for row in reader:
|
||||
sql = "INSERT IGNORE INTO words(xuhao,neirong) VALUES (%s, %s)"
|
||||
cursor.execute(sql, (row[0], row[1])) #设csv与数据库对应
|
||||
|
||||
try:
|
||||
# ...(原来的执行代码)
|
||||
cnx.commit()
|
||||
print("数据导入成功!")
|
||||
except mysql.connector.Error as err:
|
||||
print(f"数据导入失败: {err}")
|
||||
finally:
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,44 @@
|
||||
import pymysql
|
||||
|
||||
# 数据库连接配置
|
||||
db_config = {
|
||||
'host': 'localhost', # 数据库地址
|
||||
'user': 'your_username', # 数据库用户名
|
||||
'password': 'your_password', # 数据库密码
|
||||
'database': 'word', # 数据库名
|
||||
'charset': 'utf8mb4', # 字符编码
|
||||
}
|
||||
|
||||
# 待插入的数据
|
||||
data_to_insert = [
|
||||
(1, 'abandon vt.旬弃;形弃,萨瑟'),
|
||||
(2, 'ability n.能力;能耐,乃炸'),
|
||||
# ... 其他数据 ...
|
||||
# 注意:这里的每一项都是一个元组,格式为(序号, 内容)
|
||||
]
|
||||
|
||||
# 连接数据库并尝试插入数据
|
||||
try:
|
||||
connection = pymysql.connect(**db_config)
|
||||
cursor = connection.cursor()
|
||||
|
||||
# 执行批量插入
|
||||
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}")
|
||||
# 发生错误时回滚事务
|
||||
if connection:
|
||||
connection.rollback()
|
||||
finally:
|
||||
# 关闭游标和连接
|
||||
if cursor:
|
||||
cursor.close()
|
||||
if connection:
|
||||
connection.close()
|
@ -0,0 +1,94 @@
|
||||
import sqlite3
|
||||
import random
|
||||
import tkinter as tk
|
||||
from tkinter import Toplevel
|
||||
|
||||
# 数据库连接与初始化
|
||||
def init_db_connection():
|
||||
conn = sqlite3.connect('word_database.db')
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('CREATE TABLE IF NOT EXISTS Words (word TEXT, meaning TEXT, learned INTEGER)')
|
||||
conn.commit()
|
||||
return conn
|
||||
|
||||
# 获取未学习的单词
|
||||
def get_unlearned_word(conn):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT word, meaning FROM Words WHERE learned = 0 ORDER BY RANDOM() LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
return {'word': result[0], 'meaning': result[1]}
|
||||
return None
|
||||
|
||||
# 标记单词为已学习
|
||||
def mark_learned(word, conn):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('UPDATE Words SET learned = 1 WHERE word = ?', (word,))
|
||||
conn.commit()
|
||||
|
||||
# 初始化主窗口
|
||||
root = tk.Tk()
|
||||
root.title("单词学习系统")
|
||||
|
||||
|
||||
def open_new_window1(conn):
|
||||
new_window = Toplevel(root)
|
||||
new_window.title("新单词")
|
||||
|
||||
def learn_next_word():
|
||||
word = get_unlearned_word(conn)
|
||||
if word:
|
||||
label_word.config(text=word['word'])
|
||||
label_meaning.config(text=word['meaning'])
|
||||
current_word = word['word']
|
||||
else:
|
||||
tk.messagebox.showinfo("提示", "没有更多新单词了!")
|
||||
|
||||
def review_previous():
|
||||
# 实现回顾逻辑(这里简化处理,实际可能需要维护一个历史单词队列)
|
||||
pass
|
||||
|
||||
current_word = get_unlearned_word(conn)
|
||||
if current_word:
|
||||
label_word = tk.Label(new_window, text=current_word['word'])
|
||||
label_word.pack()
|
||||
|
||||
label_meaning = tk.Label(new_window, text=current_word['meaning'])
|
||||
label_meaning.pack()
|
||||
|
||||
button_next = tk.Button(new_window, text="下一个单词", command=learn_next_word)
|
||||
button_next.pack()
|
||||
|
||||
button_review = tk.Button(new_window, text="回顾", command=review_previous)
|
||||
button_review.pack()
|
||||
else:
|
||||
tk.messagebox.showinfo("提示", "没有新单词!")
|
||||
|
||||
def open_new_window2(conn):
|
||||
|
||||
|
||||
new_window = Toplevel(root)
|
||||
new_window.title("复习单词")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def open_new_window3(conn):
|
||||
new_window = Toplevel(root)
|
||||
new_window.title("易错单词")
|
||||
|
||||
# 同样,易错单词窗口逻辑需根据错误记录定制,这里简化处理
|
||||
pass
|
||||
|
||||
|
||||
button1 = tk.Button(root, text="学习新单词", command=lambda: open_new_window1(init_db_connection()))
|
||||
button1.pack(pady=10)
|
||||
|
||||
button2 = tk.Button(root, text="复习单词", command=lambda: open_new_window2(init_db_connection()))
|
||||
button2.pack(pady=10)
|
||||
|
||||
button3 = tk.Button(root, text="易错单词", command=lambda: open_new_window3(init_db_connection()))
|
||||
button3.pack(pady=10)
|
||||
|
||||
root.mainloop()
|
Binary file not shown.
Loading…
Reference in new issue