import tkinter as tk
import random

poems = [
    {
        "title": "静夜思",
        "author": "李白",
        "content": "床前明月光，\n疑是地上霜。\n举头望明月，\n低头思故乡。"
    },
    {
        "title": "登鹳雀楼",
        "author": "王之涣",
        "content": "白日依山尽，\n黄河入海流。\n欲穷千里目，\n更上一层楼。"
    },
    {
        "title": "春晓",
        "author": "孟浩然",
        "content": "春眠不觉晓，\n处处闻啼鸟。\n夜来风雨声，\n花落知多少。"
    }
]

root = tk.Tk()
root.title("奥特曼唐诗三百首")
root.geometry("600x450")
root.configure(bg="#c70000")

current_index = 0

def show_poem(index):
    poem = poems[index]
    poem_text.delete("1.0", tk.END)
    poem_text.insert(tk.END, f"{poem['title']} —— {poem['author']}\n\n")
    poem_text.insert(tk.END, poem["content"])
    print("当前诗歌索引:", index)  # 调试用

def prev_poem():
    global current_index
    current_index = (current_index - 1) % len(poems)
    show_poem(current_index)

def next_poem():
    global current_index
    current_index = (current_index + 1) % len(poems)
    show_poem(current_index)

def random_poem():
    global current_index
    current_index = random.randint(0, len(poems) - 1)
    show_poem(current_index)

# 标题
tk.Label(
    root,
    text="🌟 奥特曼唐诗三百首 🌟",
    font=("微软雅黑", 22, "bold"),
    bg="#c70000",
    fg="white"
).pack(pady=15)

# 文本框
poem_text = tk.Text(
    root,
    font=("微软雅黑", 14),
    bg="#1a1a1a",
    fg="white",
    wrap="none"
)
poem_text.pack(expand=True, fill="both", padx=20, pady=10)

show_poem(current_index)

# 按钮
btn_frame = tk.Frame(root, bg="#c70000")
btn_frame.pack(pady=15)

tk.Button(
    btn_frame, text="⬅ 上一首",
    command=prev_poem,
    bg="#ffcc00", fg="black",
    font=("微软雅黑", 12, "bold")
).pack(side="left", padx=10)

tk.Button(
    btn_frame, text="🎲 随机一首",
    command=random_poem,
    bg="#ffcc00", fg="black",
    font=("微软雅黑", 12, "bold")
).pack(side="left", padx=10)

tk.Button(
    btn_frame, text="下一首 ➡",
    command=next_poem,
    bg="#ffcc00", fg="black",
    font=("微软雅黑", 12, "bold")
).pack(side="left", padx=10)

root.mainloop()