gyt200300 6 months ago
parent f97f9a5d1c
commit 293d25f643

@ -0,0 +1,39 @@
import tkinter as tk
import csv
import random
# 从CSV读取数据
def read_words_from_csv(file_path):
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
next(reader) # 跳过表头
return list(reader)
# 随机选取固定数量的单词
def select_random_words(words, count=5):
return random.sample(words, count)
# 创建并显示单词
def display_words(window, words):
for index, (number, word) in enumerate(words, start=1):
tk.Label(window, text=f"{number}: {word}", font=("Arial", 12)).pack(pady=5)
# 主程序
def main():
# 读取单词
words = read_words_from_csv('words.csv')
window = tk.Tk()
window.title("单词学习器")
tk.Button(window, text="开始背单词",
command=lambda: display_words(tk.Toplevel(), select_random_words(words, 5))).pack(pady=10)
window.mainloop()
if __name__ == "__main__":
main()

@ -1,37 +1,33 @@
# -*- coding: gbk -*-
from typing import List
import pymysql
import pandas as pd
# -*- coding: <encoding name> -*-
import mysql
import mysql.connector
import csv
db_config = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '2141203017',
'password': '21412030117',
'database': 'word',
'charset': 'utf8mb4',
}
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 word(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()
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
extracted='data.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}")

File diff suppressed because it is too large Load Diff

@ -1,36 +1,32 @@
import pymysql
#import cryptography
# 数据库连接配置
db_config = {
'host': 'localhost', # 数据库地址
'user': 'Mysql', # 数据库用户名
'password': '2141203017', # 数据库密码
'database': 'word', # 数据库名
'charset': 'utf8mb4', # 字符编码
}
import tkinter as tk
from tkinter import messagebox
# 待插入的数据
data_to_insert = [
('1', 'abandon vt.旬弃;形弃,萨瑟'),
('2', 'ability n.能力;能耐,乃炸'),
# ... 其他数据 ...
# 注意:这里的每一项都是一个元组,格式为(序号, 内容)
]
# 单词列表
words = ["apple", "banana", "cherry", "date", "elderberry"]
# 连接数据库并尝试插入数据
try:
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
class WordApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("单词学习")
self.current_word_index = 0
self.word_label = tk.Label(self, text="", font=("Helvetica", 20))
self.word_label.pack(pady=20)
self.create_buttons()
# 执行批量插入
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))
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)
# 提交事务
connection.commit()
print("数据插入成功!")
except Exception as e:
print(f"数据插入失败,错误信息:{e}")
def show_next_word(self):
if self.current_word_index < len(words):
self.word_label.config(text=words[self.current_word_index])
self.current_word_index += 1
else:
messagebox.showinfo("结束", "所有单词已学习完毕!")
self.destroy()
if __name__ == "__main__":
app = WordApp()
app.mainloop()

@ -27,7 +27,7 @@ filename = 'extracted_data.csv'
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
csvwriter = csv.writer(csvfile)
# 写入表头
csvwriter.writerow(['序号', '内容'])
csvwriter.writerow(['序号', '内容',''])
# 写入数据
for row in data:
# 注意,原问题没有明确"单词"来源,这里假设每条数据只有序号和内容两列

@ -1,141 +1,8 @@
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):
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("复习单词")
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()
序号,内容
1,abandon vt.丢弃放弃抛弃
2,ability n.能力能耐本领
3,abnormal a.不正常的变态的
4,aboard ad.在船()上船
5,abroad ad.()国外到处
以上的csv文件创建一个窗口并设置一个按钮实现记单词的功能随机依次弹出固定数量的单词比如一次性弹出五个单词
将五个单词依次弹出并在单词下面创建两个按钮认识和不认识当点击按钮后显示下一个单词直到五个单词显示完

@ -0,0 +1,47 @@
import tkinter as tk
import csv
import random
from struct import pack
# 从CSV读取数据
def read_words_from_csv(file_path):
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
next(reader) # 过表头
return list(reader)
# 随机选取固定数量的单词
def select_random_words(words, count=5):
return random.sample(words, count)
# 创建并显示单词及按钮
def display_words(window, words, word_index, total_words):
if word_index < total_words:
number, word = word_index + 1, words[word_index][1]
tk.Label(window, text=f"{number}: {word}", font=("Arial", 12)).pack(pady=5)
tk.Button(window, text="认识", command=lambda: next_word(window, word_index +1)).pack(side=tk.LEFT, padx=10, pady=5)
tk.Button(window, text="不认识", command=lambda: next_word(window, word_index)).pack(side=tk.RIGHT, padx=1, pady=5)
else:
tk.Label(window, text="所有单词已显示完毕", font=("Arial", 14, 'bold')).pack()
def next_word(window, word_index, total_words):
window.destroy()
new_window = tk.Toplevel()
new_window.title("单词学习")
display_words(new_window, word_index, total_words)
# 主程序
def main():
# 读取单词
words = read_words_from_csv('words.csv')
window = tk.Tk()
window.title("单词学习器")
tk.Button(window, text="开始背单词",
command=lambda: display_words(tk.Toplevel(), 0, len(words))),
pack(pady=10)
window.mainloop()
if __name__=='__main__':
main()

@ -0,0 +1,71 @@
序号,内容
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
Loading…
Cancel
Save