编辑代码

import random
import tkinter as tk
from datetime import datetime

class UnderwearDivinationApp:
    def __init__(self):
        self.colors = {
            '大安': ['幸运红', '帝王金', '火焰橙'],
            '留连': ['迷幻紫', '深邃黑', '星空蓝'],
            '速喜': ['桃花粉', '活力黄', '翡翠绿'],
            '赤口': ['霸气银', '极地白', '闪电紫'],
            '小吉': ['清新蓝', '薄荷绿', '珊瑚橙'],
            '空亡': ['神秘黑', '银河灰', '暗夜蓝']
        }

        self.descriptions = {
            '大安': "稳如泰山的选择,展现你的强大气场",
            '留连': "若有似无的诱惑,让人移不开视线",
            '速喜': "充满活力的选择,带来意想不到的桃花",
            '赤口': "犀利大胆的穿搭,尽显独特个性",
            '小吉': "清新自然的选择,开启一天好运气",
            '空亡': "神秘深邃的韵味,隐藏无限可能"
        }

        self.window = tk.Tk()
        self.window.title("娱乐版小六壬内衣占")
        self.window.geometry("400x300")
        
        self.create_widgets()
    
    def create_widgets(self):
        tk.Label(self.window, text="娱乐内衣占卜", font=("楷体", 16)).pack(pady=10)
        
        tk.Label(self.window, text="输入名字:").pack()
        self.name_entry = tk.Entry(self.window)
        self.name_entry.pack()
        
        tk.Button(self.window, text="开始占卜", command=self.calculate).pack(pady=10)
        
        self.result_label = tk.Label(self.window, text="", wraplength=350)
        self.result_label.pack(pady=10)
        
        tk.Button(self.window, text="保存结果", command=self.save_result).pack()

    def get_six_stick(self):
        now = datetime.now()
        return (now.second + now.minute * 60) % 6

    def calculate(self):
        name = self.name_entry.get() or "匿名"
        hexagram = [
            "大安", "留连", "速喜",
            "赤口", "小吉", "空亡"
        ][self.get_six_stick()]

        color = random.choice(self.colors[hexagram])
        advice = [
            "今日宜大胆展示",
            "建议搭配特殊饰品",
            "可能会带来意外惊喜",
            "注意检查穿搭协调性"
        ][random.randint(0, 3)]

        result = f"{name}的专属占卜结果:\n"
        result += f"卦象:{hexagram} - {self.descriptions[hexagram]}\n"
        result += f"幸运颜色:{color}\n"
        result += f"穿搭建议:{advice}"
        
        self.result_label.config(text=result)

    def save_result(self):
        with open("underwear_result.txt", "w", encoding="utf-8") as f:
            f.write(self.result_label.cget("text"))

    def run(self):
        self.window.mainloop()

if __name__ == "__main__":
    app = UnderwearDivinationApp()
    app.run()