gyt200300 6 months ago
parent 9dded428d8
commit f97f9a5d1c

@ -6,10 +6,11 @@ import mysql.connector
import csv
db_config = {
'host': 'Mysql',
'host': 'localhost',
'user': 'root',
'password': '21412030117',
'database': 'words',
'password': '2141203017',
'database': 'word',
}
cnx = mysql.connector.connect(**db_config)
@ -21,7 +22,7 @@ with open('extracted_data.csv', mode='r', encoding='utf-8') as file:
headers = next(reader, None)
if headers is not None: # 过表头
for row in reader:
sql = "INSERT IGNORE INTO words(xuhao,neirong) VALUES (%s, %s)"
sql = "INSERT IGNORE INTO word(xuhao,neirong) VALUES (%s, %s)"
cursor.execute(sql, (row[0], row[1])) #设csv与数据库对应
try:

@ -1,18 +1,18 @@
import pymysql
#import cryptography
# 数据库连接配置
db_config = {
'host': 'localhost', # 数据库地址
'user': 'your_username', # 数据库用户名
'password': 'your_password', # 数据库密码
'user': 'Mysql', # 数据库用户名
'password': '2141203017', # 数据库密码
'database': 'word', # 数据库名
'charset': 'utf8mb4', # 字符编码
}
# 待插入的数据
data_to_insert = [
(1, 'abandon vt.旬弃;形弃,萨瑟'),
(2, 'ability n.能力;能耐,乃炸'),
('1', 'abandon vt.旬弃;形弃,萨瑟'),
('2', 'ability n.能力;能耐,乃炸'),
# ... 其他数据 ...
# 注意:这里的每一项都是一个元组,格式为(序号, 内容)
]
@ -33,12 +33,4 @@ try:
print("数据插入成功!")
except Exception as e:
print(f"数据插入失败,错误信息:{e}")
# 发生错误时回滚事务
if connection:
connection.rollback()
finally:
# 关闭游标和连接
if cursor:
cursor.close()
if connection:
connection.close()

@ -65,8 +65,55 @@ def open_new_window1(conn):
tk.messagebox.showinfo("提示", "没有新单词!")
def open_new_window2(conn):
def check_spelling():
user_input = entry_spelling.get().strip()
if user_input.lower() == current_review_word['word']:
label_spelling.config(bg='green') # 标记为绿色表示正确
mark_next_review(conn) # 正确后标记下一个复习
else:
label_spelling.config(bg='red') # 错误则标记为红色
messagebox.showerror("错误", "拼写错误,请重试。")
def review_previous_word():
global current_review_word
# 实现回顾前一个单词的逻辑,这里简化处理,假设我们有一个全局变量或列表来追踪复习单词
# 实际应用中,可能需要维护复习单词的历史栈
pass
def mark_next_review(conn):
# 假设复习完当前单词后自动标记下一个为复习状态,实际逻辑可能更复杂
global current_review_word
next_word = get_learned_word(conn)
if next_word:
current_review_word = next_word
label_meaning.config(text=next_word['meaning'])
entry_spelling.delete(0, tk.END) # 清空输入框
label_spelling.config(text="", bg='white') # 重置标签颜色和内容
else:
messagebox.showinfo("提示", "没有更多复习单词了!")
new_window = Toplevel(root)
new_window.title("复习单词")
current_review_word = get_learned_word(conn)
if current_review_word:
label_meaning = tk.Label(new_window, text=current_review_word['meaning'], wraplength=200)
label_meaning.pack(pady=10)
label_spelling = tk.Label(new_window, text="", width=20, bg='white')
label_spelling.pack(pady=5)
entry_spelling = Entry(new_window)
entry_spelling.pack(pady=5)
button_check = tk.Button(new_window, text="检查拼写", command=check_spelling)
button_check.pack(side=tk.LEFT, padx=5)
button_prev = tk.Button(new_window, text="回顾前一个", command=review_previous_word)
button_prev.pack(side=tk.LEFT, padx=5)
else:
messagebox.showinfo("提示", "没有复习单词!")
new_window = Toplevel(root)
new_window.title("复习单词")

Loading…
Cancel
Save