import tkinter as tk
from tkinter import ttk

# ========== 单词库，你可以在这里增删单词 ==========
word_list = [
    {"en": "apple", "cn": "苹果"},
    {"en": "banana", "cn": "香蕉"},
    {"en": "computer", "cn": "电脑"},
    {"en": "program", "cn": "程序"},
    {"en": "python", "cn": "蟒蛇；Python语言"},
    {"en": "student", "cn": "学生"},
    {"en": "teacher", "cn": "老师"},
    {"en": "book", "cn": "书籍"},
    {"en": "water", "cn": "水"},
    {"en": "happy", "cn": "开心的"}
]

class WordReciteApp:
    def __init__(self, root):
        self.root = root
        self.root.title("英语单词背诵器")
        self.root.geometry("500x320")

        self.current_idx = 0  # 当前单词索引
        self.known_count = 0  # 记住的单词数量
        self.is_show_cn = False  # 是否显示中文

        # 界面组件
        # 单词展示框
        self.word_label = ttk.Label(root, text="", font=("Arial", 30))
        self.word_label.pack(pady=30)

        # 提示标签（中文释义）
        self.cn_label = ttk.Label(root, text="", font=("SimHei", 18), foreground="#222222")
        self.cn_label.pack()

        # 状态栏
        self.status_label = ttk.Label(root, text="")
        self.status_label.pack(pady=10)

        # 按钮容器
        frame_btn = ttk.Frame(root)
        frame_btn.pack(pady=10)

        ttk.Button(frame_btn, text="显示/隐藏释义", command=self.toggle_cn).grid(row=0, column=0, padx=5)
        ttk.Button(frame_btn, text="上一个", command=self.prev_word).grid(row=0, column=1, padx=5)
        ttk.Button(frame_btn, text="下一个", command=self.next_word).grid(row=0, column=2, padx=5)
        ttk.Button(frame_btn, text="✅记住了", command=self.mark_known).grid(row=1, column=0, padx=5, pady=4)
        ttk.Button(frame_btn, text="❌还不会", command=self.mark_unknown).grid(row=1, column=1, padx=5, pady=4)
        ttk.Button(frame_btn, text="重置进度", command=self.reset).grid(row=1, column=2, padx=5, pady=4)

        self.update_display()

    def update_display(self):
        """刷新界面文字"""
        word = word_list[self.current_idx]
        self.word_label.config(text=word["en"])
        if self.is_show_cn:
            self.cn_label.config(text=word["cn"])
        else:
            self.cn_label.config(text="")
        total = len(word_list)
        self.status_label.config(text=f"单词 {self.current_idx+1}/{total}  |  已记住：{self.known_count}")

    def toggle_cn(self):
        """切换中文释义显示"""
        self.is_show_cn = not self.is_show_cn
        self.update_display()

    def next_word(self):
        """下一个单词"""
        if self.current_idx < len(word_list)-1:
            self.current_idx += 1
            self.is_show_cn = False
            self.update_display()

    def prev_word(self):
        """上一个单词"""
        if self.current_idx > 0:
            self.current_idx -= 1
            self.is_show_cn = False
            self.update_display()

    def mark_known(self):
        self.known_count += 1
        self.next_word()

    def mark_unknown(self):
        self.next_word()

    def reset(self):
        """重置背诵进度"""
        self.current_idx = 0
        self.known_count = 0
        self.is_show_cn = False
        self.update_display()


if __name__ == "__main__":
    root = tk.Tk()
    app = WordReciteApp(root)
    root.mainloop()
