import tkinter as tk
from datetime import datetime

# 星座数据
ZODIAC_SIGNS = [
    ("摩羯座", (1, 1), (1, 19)),
    ("水瓶座", (1, 20), (2, 18)),
    ("双鱼座", (2, 19), (3, 20)),
    ("白羊座", (3, 21), (4, 19)),
    ("金牛座", (4, 20), (5, 20)),
    ("双子座", (5, 21), (6, 21)),
    ("巨蟹座", (6, 22), (7, 22)),
    ("狮子座", (7, 23), (8, 22)),
    ("处女座", (8, 23), (9, 22)),
    ("天秤座", (9, 23), (10, 23)),
    ("天蝎座", (10, 24), (11, 22)),
    ("射手座", (11, 23), (12, 21)),
    ("摩羯座", (12, 22), (12, 31)),
]

# 生肖
CHINESE_ZODIAC = [
     "鼠", "牛","虎", "兔", 
     "龙", "蛇","马","羊",
     "猴", "鸡","狗", "猪"
]


def get_zodiac_sign(month, day):
    for name, start, end in ZODIAC_SIGNS:
        if (month == start[0] and day >= start[1]) or \
           (month == end[0] and day <= end[1]):
            return name
    return "未知"


def get_chinese_zodiac(year):
    # 以1900年为猴年基准
    return CHINESE_ZODIAC[(year - 1900) % 12]


def query():
    try:
        birth_str = entry_date.get().strip()
        birth_date = datetime.strptime(birth_str, "%Y-%m-%d")

        zodiac = get_zodiac_sign(birth_date.month, birth_date.day)
        shengxiao = get_chinese_zodiac(birth_date.year)

        result_var.set(f"星座：{zodiac}\n生肖：{shengxiao}")
    except ValueError:
        result_var.set("⚠ 请输入正确日期格式：YYYY-MM-DD")


# ---------- GUI ----------
root = tk.Tk()
root.title("星座 / 生肖查询器")
root.geometry("300x200")
root.resizable(False, False)

tk.Label(root, text="请输入出生日期").pack(pady=5)
entry_date = tk.Entry(root, justify="center")
entry_date.pack()

tk.Button(root, text="查询", command=query).pack(pady=10)

result_var = tk.StringVar()
tk.Label(root, textvariable=result_var, font=("微软雅黑", 10)).pack(pady=10)

root.mainloop()
