
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import json
import os
from datetime import datetime

# 生日数据文件（本地保存）
DATA_FILE = "birthdays.json"

class BirthdayReminder:
    def __init__(self, root):
        self.root = root
        self.root.title("🎂 生日提醒器")
        self.root.geometry("550x400")
        self.root.resizable(False, False)

        # ===================== 【全新深空蓝高级配色】 =====================
        self.root.configure(bg="#edf2fa")
        self.style = ttk.Style()
        self.style.theme_use("clam")
        # 深空蓝按钮
        self.style.configure("TButton", font=("微软雅黑", 10), padding=6, borderwidth=0,background="#94b8e8",foreground="#ffffff")
        # 表格美化
        self.style.configure("Treeview", font=("微软雅黑", 9), rowheight=28, background="#ffffff", fieldbackground="#ffffff")
        self.style.configure("Treeview.Heading", font=("微软雅黑", 10, "bold"), background="#b4cdea", foreground="#253b5b")
        self.style.map("Treeview", background=[("selected", "#7fa8d8")])
        # ===================================================================

        # 加载生日数据
        self.birthdays = self.load_birthdays()

        # 界面布局
        self.create_widgets()
        
        # 启动时检查当天生日
        self.check_today_birthdays()

    # 从本地文件加载生日数据
    def load_birthdays(self):
        if os.path.exists(DATA_FILE):
            with open(DATA_FILE, "r", encoding="utf-8") as f:
                return json.load(f)
        return []

    # 保存生日数据到本地文件
    def save_birthdays(self):
        with open(DATA_FILE, "w", encoding="utf-8") as f:
            json.dump(self.birthdays, f, ensure_ascii=False, indent=2)

    # 创建界面组件
    def create_widgets(self):
        # 顶部按钮区
        frame_btn = tk.Frame(self.root, bg="#edf2fa")
        frame_btn.pack(pady=12)

        ttk.Button(frame_btn, text="➕ 添加生日", command=self.add_birthday).grid(row=0, column=0, padx=5)
        ttk.Button(frame_btn, text="❌ 删除选中", command=self.delete_birthday).grid(row=0, column=1, padx=5)
        ttk.Button(frame_btn, text="🔍 今日生日", command=self.check_today_birthdays).grid(row=0, column=2, padx=5)

        # 生日列表
        self.tree = ttk.Treeview(self.root, columns=("name", "date", "type", "note"), show="headings")
        self.tree.heading("name", text="姓名")
        self.tree.heading("date", text="生日日期")
        self.tree.heading("type", text="类型")
        self.tree.heading("note", text="备注")
        
        self.tree.column("name", width=100, anchor="center")
        self.tree.column("date", width=120, anchor="center")
        self.tree.column("type", width=80, anchor="center")
        self.tree.column("note", width=220, anchor="center")
        
        self.tree.pack(fill=tk.BOTH, expand=True, padx=12)

        # 刷新列表
        self.refresh_list()

    # 刷新生日列表
    def refresh_list(self):
        for item in self.tree.get_children():
            self.tree.delete(item)
        for b in self.birthdays:
            self.tree.insert("", tk.END, values=(b["name"], b["date"], b["type"], b["note"]))

    # 添加生日
    def add_birthday(self):
        name = simpledialog.askstring("输入", "请输入姓名：")
        if not name:
            return
        
        date = simpledialog.askstring("输入", "请输入生日（格式：MM-DD）\n例如：05-20、12-31")
        if not date or len(date) != 5 or date[2] != "-":
            messagebox.showerror("错误", "格式错误！请使用 MM-DD")
            return

        b_type = simpledialog.askstring("输入", "公历/农历？（输入：公历 或 农历）")
        if not b_type:
            b_type = "公历"

        note = simpledialog.askstring("输入", "备注（可不填）：")
        if not note:
            note = "无"

        new_birth = {
            "name": name,
            "date": date,
            "type": b_type,
            "note": note
        }

        self.birthdays.append(new_birth)
        self.save_birthdays()
        self.refresh_list()
        messagebox.showinfo("成功", "✅ 生日添加成功！")

    # 删除选中的生日
    def delete_birthday(self):
        selected = self.tree.selection()
        if not selected:
            messagebox.showwarning("提示", "请先选择一条记录")
            return
        
        self.birthdays.pop(self.tree.index(selected[0]))
        self.save_birthdays()
        self.refresh_list()
        messagebox.showinfo("成功", "🗑️ 删除成功！")

    # 检查今天的生日（核心提醒功能）
    def check_today_birthdays(self):
        today = datetime.now().strftime("%m-%d")
        today_birth = [b for b in self.birthdays if b["date"] == today]

        if not today_birth:
            messagebox.showinfo("今日", "📅 今天没有生日哦～")
            return

        # 拼接提醒消息
        msg = "🎉 今天是以下朋友的生日！\n\n"
        for b in today_birth:
            msg += f"👤 {b['name']}（{b['type']}）\n📝 {b['note']}\n\n"
        
        messagebox.showinfo("🎂 生日提醒", msg)

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

import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import json
import os
from datetime import datetime

# 生日数据文件（本地保存）
DATA_FILE = "birthdays.json"

class BirthdayReminder:
    def __init__(self, root):
        self.root = root
        self.root.title("🎂 生日提醒器")
        self.root.geometry("550x400")
        self.root.resizable(False, False)

        # ===================== 【暗夜黑｜极简高级黑主题】 =====================
        self.root.configure(bg="#2b2b2b")
        self.style = ttk.Style()
        self.style.theme_use("clam")
        # 暗夜按钮配色
        self.style.configure("TButton", font=("微软雅黑", 10), padding=6, borderwidth=0,background="#444444",foreground="#f0f0f0")
        # 表格美化
        self.style.configure("Treeview", font=("微软雅黑", 9), rowheight=28, background="#383838", fieldbackground="#383838",foreground="#eeeeee")
        self.style.configure("Treeview.Heading", font=("微软雅黑", 10, "bold"), background="#505050", foreground="#ffffff")
        self.style.map("Treeview", background=[("selected", "#606060")])
        # ===================================================================

        # 加载生日数据
        self.birthdays = self.load_birthdays()

        # 界面布局
        self.create_widgets()
        
        # 启动时检查当天生日
        self.check_today_birthdays()

    # 从本地文件加载生日数据
    def load_birthdays(self):
        if os.path.exists(DATA_FILE):
            with open(DATA_FILE, "r", encoding="utf-8") as f:
                return json.load(f)
        return []

    # 保存生日数据到本地文件
    def save_birthdays(self):
        with open(DATA_FILE, "w", encoding="utf-8") as f:
            json.dump(self.birthdays, f, ensure_ascii=False, indent=2)

    # 创建界面组件
    def create_widgets(self):
        # 顶部按钮区
        frame_btn = tk.Frame(self.root, bg="#2b2b2b")
        frame_btn.pack(pady=12)

        ttk.Button(frame_btn, text="➕ 添加生日", command=self.add_birthday).grid(row=0, column=0, padx=5)
        ttk.Button(frame_btn, text="❌ 删除选中", command=self.delete_birthday).grid(row=0, column=1, padx=5)
        ttk.Button(frame_btn, text="🔍 今日生日", command=self.check_today_birthdays).grid(row=0, column=2, padx=5)

        # 生日列表
        self.tree = ttk.Treeview(self.root, columns=("name", "date", "type", "note"), show="headings")
        self.tree.heading("name", text="姓名")
        self.tree.heading("date", text="生日日期")
        self.tree.heading("type", text="类型")
        self.tree.heading("note", text="备注")
        
        self.tree.column("name", width=100, anchor="center")
        self.tree.column("date", width=120, anchor="center")
        self.tree.column("type", width=80, anchor="center")
        self.tree.column("note", width=220, anchor="center")
        
        self.tree.pack(fill=tk.BOTH, expand=True, padx=12)

        # 刷新列表
        self.refresh_list()

    # 刷新生日列表
    def refresh_list(self):
        for item in self.tree.get_children():
            self.tree.delete(item)
        for b in self.birthdays:
            self.tree.insert("", tk.END, values=(b["name"], b["date"], b["type"], b["note"]))

    # 添加生日
    def add_birthday(self):
        name = simpledialog.askstring("输入", "请输入姓名：")
        if not name:
            return
        
        date = simpledialog.askstring("输入", "请输入生日（格式：MM-DD）\n例如：05-20、12-31")
        if not date or len(date) != 5 or date[2] != "-":
            messagebox.showerror("错误", "格式错误！请使用 MM-DD")
            return

        b_type = simpledialog.askstring("输入", "公历/农历？（输入：公历 或 农历）")
        if not b_type:
            b_type = "公历"

        note = simpledialog.askstring("输入", "备注（可不填）：")
        if not note:
            note = "无"

        new_birth = {
            "name": name,
            "date": date,
            "type": b_type,
            "note": note
        }

        self.birthdays.append(new_birth)
        self.save_birthdays()
        self.refresh_list()
        messagebox.showinfo("成功", "✅ 生日添加成功！")

    # 删除选中的生日
    def delete_birthday(self):
        selected = self.tree.selection()
        if not selected:
            messagebox.showwarning("提示", "请先选择一条记录")
            return
        
        self.birthdays.pop(self.tree.index(selected[0]))
        self.save_birthdays()
        self.refresh_list()
        messagebox.showinfo("成功", "🗑️ 删除成功！")

    # 检查今天的生日（核心提醒功能）
    def check_today_birthdays(self):
        today = datetime.now().strftime("%m-%d")
        today_birth = [b for b in self.birthdays if b["date"] == today]

        if not today_birth:
            messagebox.showinfo("今日", "📅 今天没有生日哦～")
            return

        # 拼接提醒消息
        msg = "🎉 今天是以下朋友的生日！\n\n"
        for b in today_birth:
            msg += f"👤 {b['name']}（{b['type']}）\n📝 {b['note']}\n\n"
        
        messagebox.showinfo("🎂 生日提醒", msg)

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