import tkinter as tk
from tkinter import messagebox

#唐诗数据
tang_poems = [{'title': '静夜思', 'author': '李白', 'content': '''床前明月光，
疑是地上霜。
举头望明月，
低头思故乡。'''}, {'title': '春晓', 'author': '孟浩然', 'content': '''春眠不觉晓，
处处闻啼鸟。
夜来风雨声，
花落知多少。'''}, {'title': '登鹳雀楼', 'author': '王之涣', 'content': '''白日依山尽，
黄河入海流。
欲穷千里目，
更上一层楼。'''}, {'title': '江雪', 'author': '柳宗元', 'content': '''千山鸟飞绝，
万径人踪灭。
孤舟蓑笠翁，
独钓寒江雪。'''}, {'title': '相思', 'author': '王维', 'content': '''红豆生南国，
春来发几枝。
愿君多采撷，
此物最相思。'''}, {'title': '咏鹅', 'author': '骆宾王', 'content': '''鹅鹅鹅，
曲项向天歌。
白毛浮绿水，
红掌拨清波。'''}, {'title': '悯农', 'author': '李绅', 'content': '''锄禾日当午，
汗滴禾下土。
谁知盘中餐，
粒粒皆辛苦。'''}, {'title': '游子吟', 'author': '孟郊', 'content': '''慈母手中线，游子身上衣。
临行密密缝，意恐迟迟归。
谁言寸草心，报得三春晖。'''}, {'title': '离思', 'author': '元稹', 'content': '''曾经沧海难为水，
除却巫山不是云。
取次花丛懒回顾，
半缘修道半缘君。'''}, {'title': '望庐山瀑布', 'author': '李白', 'content': '''日照香炉生紫烟，
遥看瀑布挂前川。
飞流直下三千尺，
疑是银河落九天。'''}]

class PoemApp:
    def __init__(self, root):
        self.root = root
        self.root.title("唐诗十首鉴赏")
        self.root.geometry("500x400")
        self.root.configure(bg="#f5f5dc")  # 米黄色背景，更有古风感

        # 左侧列表框标题
        label_list = tk.Label(root, text="诗歌目录", bg="#f5f5dc", font=("微软雅黑", 12, "bold"))
        label_list.pack(side="left", anchor="n", padx=10, pady=10)

        # 左侧诗歌列表
        self.poem_listbox = tk.Listbox(root, width=15, height=15, font=("微软雅黑", 11))
        self.poem_listbox.pack(side="left", fill="y", padx=10, pady=10)
        self.poem_listbox.bind('<<ListboxSelect>>', self.show_poem)

        # 填充列表内容
        for poem in tang_poems:
            self.poem_listbox.insert(tk.END, poem["title"])

        # 右侧显示区域
        self.display_frame = tk.Frame(root, bg="#ffffff", relief="sunken", bd=2)
        self.display_frame.pack(side="right", expand=True, fill="both", padx=10, pady=10)

        self.title_label = tk.Label(self.display_frame, text="请选择一首诗", font=("微软雅黑", 16, "bold"), bg="#ffffff")
        self.title_label.pack(pady=10)

        self.author_label = tk.Label(self.display_frame, text="", font=("微软雅黑", 10, "italic"), bg="#ffffff", fg="gray")
        self.author_label.pack(pady=5)

        self.content_label = tk.Label(self.display_frame, text="", font=("楷体", 14), bg="#ffffff", justify="center")
        self.content_label.pack(expand=True)

    def show_poem(self, event):
        # 获取选中的索引
        selection = self.poem_listbox.curselection()
        if selection:
            index = selection[0]
            poem = tang_poems[index]

            # 更新右侧内容
            self.title_label.config(text=poem["title"])
            self.author_label.config(text=f"作者：{poem['author']}")
            self.content_label.config(text=poem["content"])

#米黄色背景，更有古风感

#左侧列表框标题

#左侧诗歌列表

#填充列表内容

#右侧显示区域

#获取选中的索引

#更新右侧内容

if (__name__ == '__main__'):
    root = tk.Tk()
    app = PoemApp(root)
    root.mainloop()
