import tkinter as tk
from tkinter import font

# 内置唐诗库（精选经典唐诗，模拟三百首效果）
poem_list = [
    {"title": "静夜思", "author": "李白", "content": "床前明月光，\n疑是地上霜。\n举头望明月，\n低头思故乡。"},
    {"title": "春晓", "author": "孟浩然", "content": "春眠不觉晓，\n处处闻啼鸟。\n夜来风雨声，\n花落知多少。"},
    {"title": "咏鹅", "author": "骆宾王", "content": "鹅，鹅，鹅，\n曲项向天歌。\n白毛浮绿水，\n红掌拨清波。"},
    {"title": "登鹳雀楼", "author": "王之涣", "content": "白日依山尽，\n黄河入海流。\n欲穷千里目，\n更上一层楼。"},
    {"title": "相思", "author": "王维", "content": "红豆生南国，\n春来发几枝。\n愿君多采撷，\n此物最相思。"},
    {"title": "九月九日忆山东兄弟", "author": "王维", "content": "独在异乡为异客，\n每逢佳节倍思亲。\n遥知兄弟登高处，\n遍插茱萸少一人。"},
    {"title": "望庐山瀑布", "author": "李白", "content": "日照香炉生紫烟，\n遥看瀑布挂前川。\n飞流直下三千尺，\n疑是银河落九天。"},
    {"title": "早发白帝城", "author": "李白", "content": "朝辞白帝彩云间，\n千里江陵一日还。\n两岸猿声啼不住，\n轻舟已过万重山。"},
    {"title": "绝句", "author": "杜甫", "content": "两个黄鹂鸣翠柳，\n一行白鹭上青天。\n窗含西岭千秋雪，\n门泊东吴万里船。"},
    {"title": "江雪", "author": "柳宗元", "content": "千山鸟飞绝，\n万径人踪灭。\n孤舟蓑笠翁，\n独钓寒江雪。"},
    {"title": "赋得古原草送别", "author": "白居易", "content": "离离原上草，一岁一枯荣。\n野火烧不尽，春风吹又生。\n远芳侵古道，晴翠接荒城。\n又送王孙去，萋萋满别情。"},
    {"title": "清明", "author": "杜牧", "content": "清明时节雨纷纷，\n路上行人欲断魂。\n借问酒家何处有？\n牧童遥指杏花村。"},
    {"title": "山行", "author": "杜牧", "content": "远上寒山石径斜，\n白云生处有人家。\n停车坐爱枫林晚，\n霜叶红于二月花。"},
    {"title": "游子吟", "author": "孟郊", "content": "慈母手中线，游子身上衣。\n临行密密缝，意恐迟迟归。\n谁言寸草心，报得三春晖。"},
    {"title": "枫桥夜泊", "author": "张继", "content": "月落乌啼霜满天，\n江枫渔火对愁眠。\n姑苏城外寒山寺，\n夜半钟声到客船。"}
]

# 当前页码
current_page = 0

# 创建主窗口
root = tk.Tk()
root.title("古风唐诗三百首")
root.geometry("520x720")
root.resizable(False, False)
# 仿古宣纸底色
root.config(bg="#F5EEDC")

# 古风字体兼容
try:
    title_font = font.Font(family="楷体", size=26, weight="bold")
    author_font = font.Font(family="楷体", size=16)
    poem_font = font.Font(family="楷体", size=20)
    btn_font = font.Font(family="宋体", size=16)
except:
    title_font = font.Font(size=26, weight="bold")
    author_font = font.Font(size=16)
    poem_font = font.Font(size=20)
    btn_font = font.Font(size=16)

# 切换诗词函数
def refresh_poem():
    poem = poem_list[current_page]
    var_title.set(poem["title"])
    var_author.set(f"—— {poem['author']}")
    text_content.delete(1.0, tk.END)
    text_content.insert(tk.END, poem["content"])
    var_page_text.set(f"第 {current_page + 1} / {len(poem_list)} 首")

# 上一首
def prev_poem():
    global current_page
    if current_page > 0:
        current_page -= 1
        refresh_poem()

# 下一首
def next_poem():
    global current_page
    if current_page < len(poem_list) - 1:
        current_page += 1
        refresh_poem()

# 回到第一首
def reset_all():
    global current_page
    current_page = 0
    refresh_poem()

# ---------------------- 界面布局 ----------------------
# 顶部大标题
var_title = tk.StringVar()
lab_top_title = tk.Label(
    root, textvariable=var_title,
    font=title_font, bg="#F5EEDC", fg="#8C2318"
)
lab_top_title.pack(pady=20)

# 作者行
var_author = tk.StringVar()
lab_author = tk.Label(
    root, textvariable=var_author,
    font=author_font, bg="#F5EEDC", fg="#593822"
)
lab_author.pack(pady=(0, 15))

# 诗词文本框（红木纹边框）
frame_text_box = tk.Frame(root, bg="#8C2318", bd=7, relief=tk.RIDGE)
frame_text_box.pack(padx=30)

text_content = tk.Text(
    frame_text_box, width=22, height=12,
    font=poem_font, bg="#FFF9E8", fg="#222222",
    bd=0, padx=15, pady=15
)
text_content.pack()

# 页码显示
var_page_text = tk.StringVar()
lab_page = tk.Label(
    root, textvariable=var_page_text,
    font=author_font, bg="#F5EEDC", fg="#664433"
)
lab_page.pack(pady=18)

# 按钮容器
frame_btn = tk.Frame(root, bg="#F5EEDC")
frame_btn.pack(pady=5)

# 按钮古风配色
style_btn_wood = {"bg":"#C4936B", "fg":"white", "activebackground":"#9E704E"}
style_btn_red = {"bg":"#A6341B", "fg":"white", "activebackground":"#7A2514"}

btn_prev = tk.Button(frame_btn, text="上一首", width=7, height=2, font=btn_font, command=prev_poem,**style_btn_wood)
btn_reset = tk.Button(frame_btn, text="首页", width=7, height=2, font=btn_font, command=reset_all,**style_btn_red)
btn_next = tk.Button(frame_btn, text="下一首", width=7, height=2, font=btn_font, command=next_poem,**style_btn_wood)

btn_prev.grid(row=0, column=0, padx=8)
btn_reset.grid(row=0, column=1, padx=8)
btn_next.grid(row=0, column=2, padx=8)

# 底部落款
lab_foot = tk.Label(
    root, text="墨香诗卷 · 古风唐诗",
    font=font.Font(size=13), bg="#F5EEDC", fg="#704830"
)
lab_foot.pack(pady=40)

# 初始化加载第一首
refresh_poem()

root.mainloop()