import tkinter as tk
from tkinter import messagebox

# 唐诗数据（精选30首）
poems = [
    {"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意恐迟迟归。\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远芳侵古道，晴翠接荒城。\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早有蜻蜓立上头。"}
]

class PoemApp:
    def __init__(self, root):
        self.root = root
        self.root.title("唐诗精选30首")
        self.root.geometry("600x450")
        self.root.configure(bg="#f5f5dc") # 米黄色背景，更有书卷气

        # 左侧列表框
        self.list_frame = tk.Frame(root, bg="#f5f5dc")
        self.list_frame.pack(side="left", fill="y", padx=10, pady=10)

        self.label = tk.Label(self.list_frame, text="诗词目录", font=("微软雅黑", 12, "bold"), bg="#f5f5dc")
        self.label.pack()

        self.scrollbar = tk.Scrollbar(self.list_frame)
        self.scrollbar.pack(side="right", fill="y")

        self.poem_list = tk.Listbox(self.list_frame, font=("微软雅黑", 10), width=20, 
                                    yscrollcommand=self.scrollbar.set, bg="#fffaf0")
        for p in poems:
            self.poem_list.insert(tk.END, p["title"])
        self.poem_list.pack(side="left", fill="both", expand=True)
        self.scrollbar.config(command=self.poem_list.yview)
        
        # 绑定点击事件
        self.poem_list.bind('<<ListboxSelect>>', self.show_poem)

        # 右侧内容显示区
        self.content_frame = tk.Frame(root, bg="#ffffff", relief="sunken", borderwidth=1)
        self.content_frame.pack(side="right", fill="both", expand=True, padx=10, pady=10)

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

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

        self.text_content = tk.Label(self.content_frame, text="", font=("楷体", 16), bg="#ffffff", justify="center")
        self.text_content.pack(pady=20)

    def show_poem(self, event):
        # 获取选中的索引
        selection = self.poem_list.curselection()
        if selection:
            index = selection[0]
            poem = poems[index]
            self.title_label.config(text=poem["title"])
            self.author_label.config(text=f"作者：[{poem['author']}]")
            self.text_content.config(text=poem["content"])

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