import tkinter as tk
from tkinter import ttk
import random

# 星座基础数据
constellation_data = [
    {"name": "白羊座", "date": "3.21-4.19"},
    {"name": "金牛座", "date": "4.20-5.20"},
    {"name": "双子座", "date": "5.21-6.21"},
    {"name": "巨蟹座", "date": "6.22-7.22"},
    {"name": "狮子座", "date": "7.23-8.22"},
    {"name": "处女座", "date": "8.23-9.22"},
    {"name": "天秤座", "date": "9.23-10.23"},
    {"name": "天蝎座", "date": "10.24-11.22"},
    {"name": "射手座", "date": "11.23-12.21"},
    {"name": "摩羯座", "date": "12.22-1.19"},
    {"name": "水瓶座", "date": "1.20-2.18"},
    {"name": "双鱼座", "date": "2.19-3.20"},
]

# 娱乐运势文案库
fortune_texts = [
    "今天整体状态不错，适合主动出击，大胆尝试新想法。",
    "遇事多冷静思考，不要冲动做决定，稳扎稳打为宜。",
    "人缘运势上升，适合社交沟通，容易得到他人帮助。",
    "情绪略有起伏，学会调整心态，小事不必耿耿于怀。",
    "机遇悄悄降临，多留意身边信息，把握难得机会。",
    "财运平平，不适合大额消费与投资，理性花钱。",
    "灵感迸发，创意十足，工作学习效率会有所提升。",
    "适合独处休整，给自己一点放松的时间，养精蓄锐。",
    "人际方面避免口舌之争，退让一步海阔天空。",
    "期待的事情有望迎来进展，保持乐观耐心等待消息。"
]

lucky_colors = ["天蓝色", "樱花粉", "浅紫色", "薄荷绿", "香槟金", "象牙白", "珊瑚橙", "银灰色"]
luck_numbers = [1, 3, 5, 6, 8, 9, 12, 16, 19, 22]

def get_fortune():
    """生成随机星座运势"""
    select_name = combo.get()
    if not select_name:
        result_text.set("请先选择你的星座！")
        return

    # 查找星座日期
    info = next(item for item in constellation_data if item["name"] == select_name)
    fortune = random.choice(fortune_texts)
    color = random.choice(lucky_colors)
    num = random.choice(luck_numbers)
    star = random.randint(3, 5)  # 运势星级3~5星

    output = f"【{info['name']}】{info['date']}\n"
    output += f"今日运势：{fortune}\n"
    output += f"幸运颜色：{color}\n"
    output += f"幸运数字：{num}\n"
    output += f"运势星级：{'★' * star}{'☆'*(5-star)}"

    result_text.set(output)

# 创建主窗口
root = tk.Tk()
root.title("星座运势查询（娱乐版）")
root.geometry("460x360")
root.resizable(False, False)

# 标题
title_label = tk.Label(root, text="✨星座运势小程序✨", font=("微软雅黑", 16, "bold"))
title_label.pack(pady=15)

# 选择区域
frame_select = tk.Frame(root)
frame_select.pack(pady=5)
tk.Label(frame_select, text="选择星座：", font=("微软雅黑", 11)).grid(row=0, column=0, padx=5)

combo = ttk.Combobox(frame_select, width=12, font=("微软雅黑", 11), state="readonly")
combo["values"] = [c["name"] for c in constellation_data]
combo.grid(row=0, column=1, padx=5)

query_btn = tk.Button(root, text="查询今日运势", command=get_fortune,
                      font=("微软雅黑", 11), bg="#4488dd", fg="white")
query_btn.pack(pady=12)

# 结果展示
result_text = tk.StringVar()
result_label = tk.Label(root, textvariable=result_text, font=("微软雅黑", 10),
                        justify="left", wraplength=420)
result_label.pack(pady=10)

# 底部提示
tip_label = tk.Label(root, text="⚠本程序仅供娱乐，请勿当真", font=("微软雅黑",9), fg="#888888")
tip_label.pack(side="bottom", pady=10)

root.mainloop()