import tkinter as tk
from tkinter import messagebox

class VocabularyApp:
    def __init__(self, root):
        self.root = root
        self.root.title("英语单词背诵神器")
        self.root.geometry("400x300")
        
        # --- 1. 单词数据库 (你可以从这里扩展，或者读取外部文件) ---
        self.vocabulary = [
            {"word": "Ambiguous", "pos": "adj.", "meaning": "模棱两可的；含糊不清的"},
            {"word": "Benevolent", "pos": "adj.", "meaning": "仁慈的；慈善的"},
            {"word": "Candid", "pos": "adj.", "meaning": "正直的；坦白的"},
            {"word": "Diligent", "pos": "adj.", "meaning": "勤勉的；用功的"},
            {"word": "Eloquent", "pos": "adj.", "meaning": "雄辩的；有口才的"},
            {"word": "Fluctuate", "pos": "v.", "meaning": "波动；涨落"},
            {"word": "Generous", "pos": "adj.", "meaning": "慷慨的；大方的"},
            {"word": "Hypothesis", "pos": "n.", "meaning": "假设；假说"},
        ]
        
        self.current_index = 0
        self.show_meaning = False

        # --- 2. 界面布局 ---
        
        # 顶部标签
        self.lbl_word = tk.Label(root, text="", font=("Arial", 24, "bold"), pady=20)
        self.lbl_word.pack()

        self.lbl_pos = tk.Label(root, text="", font=("Arial", 12, "italic"), fg="#555555")
        self.lbl_pos.pack()

        # 释义区域
        self.lbl_meaning = tk.Label(root, text="", font=("Arial", 14), fg="#0066cc", pady=10)
        self.lbl_meaning.pack()

        # 按钮区域
        self.btn_frame = tk.Frame(root)
        self.btn_frame.pack(pady=20)

        self.btn_prev = tk.Button(self.btn_frame, text="<< 上一个", command=self.prev_word, width=10)
        self.btn_prev.pack(side=tk.LEFT, padx=10)

        self.btn_toggle = tk.Button(self.btn_frame, text="显示/隐藏释义", command=self.toggle_meaning, width=15, bg="#e1e1e1")
        self.btn_toggle.pack(side=tk.LEFT, padx=10)

        self.btn_next = tk.Button(self.btn_frame, text="下一个 >>", command=self.next_word, width=10)
        self.btn_next.pack(side=tk.LEFT, padx=10)

        # 进度标签
        self.lbl_progress = tk.Label(root, text="", fg="#888888", font=("Arial", 10))
        self.lbl_progress.pack(side=tk.BOTTOM, pady=10)

        # --- 3. 初始化显示 ---
        self.update_display()

    def update_display(self):
        # 获取当前单词数据
        current_data = self.vocabulary[self.current_index]
        
        # 更新单词和词性
        self.lbl_word.config(text=current_data['word'])
        self.lbl_pos.config(text=current_data['pos'])
        
        # 更新释义（根据开关状态决定是否显示）
        if self.show_meaning:
            self.lbl_meaning.config(text=current_data['meaning'])
        else:
            self.lbl_meaning.config(text="") # 隐藏时显示空字符串，或者显示 "点击显示释义"

        # 更新进度
        self.lbl_progress.config(text=f"进度: {self.current_index + 1} / {len(self.vocabulary)}")

    def toggle_meaning(self):
        self.show_meaning = not self.show_meaning
        self.update_display()

    def next_word(self):
        if self.current_index < len(self.vocabulary) - 1:
            self.current_index += 1
            self.show_meaning = False # 切换到下一个词时，自动隐藏释义
            self.update_display()
        else:
            messagebox.showinfo("提示", "已经是最后一个单词了！")

    def prev_word(self):
        if self.current_index > 0:
            self.current_index -= 1
            self.show_meaning = False # 切换到上一个词时，自动隐藏释义
            self.update_display()
        else:
            messagebox.showinfo("提示", "已经是第一个单词了！")

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
















