You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
import tkinter as tk
|
|
from tkinter import messagebox
|
|
import random
|
|
import pymysql
|
|
import test
|
|
|
|
|
|
class Window3(tk.Toplevel):
|
|
def __init__(self, master):
|
|
super().__init__(master)
|
|
self.title("易错单词复习")
|
|
self.geometry("400x300")
|
|
|
|
# 数据库连接设置
|
|
|
|
self.cursor = self.db.cursor()
|
|
self.text_widget = tk.Text(self, wrap=tk.WORD, width=40, height=10)
|
|
self.text_widget.pack(expand=True, fill=tk.BOTH, padx=10, pady=10)
|
|
|
|
# 获取易错单词
|
|
self.fetch_and_display_mistaken_words()
|
|
|
|
def fetch_and_display_mistaken_words(self):
|
|
self.cursor.execute("SELECT `word`, `meaning` FROM `words` WHERE `easily_mistaken` = 1")
|
|
mistaken_words = self.cursor.fetchall()
|
|
if mistaken_words:
|
|
self.display_words(mistaken_words)
|
|
else:
|
|
messagebox.showinfo("提示", "没有易错单词可供复习!")
|
|
self.destroy()
|
|
|
|
def display_words(self, words):
|
|
# 使用Text控件显示单词和意义
|
|
for idx, word_info in enumerate(words, start=1):
|
|
text_to_insert = f"{idx}. 单词: {word_info['word']}, 意义: {word_info['meaning']}\n"
|
|
self.text_widget.insert(tk.END, text_to_insert)
|
|
|
|
# 自动滚动到底部
|
|
self.text_widget.see(tk.END)
|
|
|
|
def on_closing(self):
|
|
self.db.close()
|
|
self.destroy() |