import tkinter as tk
from tkinter import ttk,messagebox
import random

# 暗黑风天气查询（无联网API、永不报错、内置城市天气）
class WeatherApp:
    def __init__(self,root):
        self.root=root
        self.root.title("🌤️ 天气查询小工具")
        self.root.geometry("400x300")
        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=5,background="#444444",foreground="#f0f0f0")

        # 本地模拟天气数据
        self.weather_dict={
            "北京":["晴","多云","轻度雾霾"],
            "上海":["小雨","阴天","多云"],
            "广州":["雷阵雨","闷热","晴天"],
            "重庆":["阴天","雾天","潮湿"],
            "南京":["多云","晴天","微风"],
            "成都":["阴天","多云","湿润"]
        }
        self.create_ui()

    def create_ui(self):
        tk.Label(self.root,text="🌎 城市天气查询",bg="#2b2b2b",fg="white",font=("微软雅黑",14)).pack(pady=15)
        tk.Label(self.root,text="选择城市：",bg="#2b2b2b",fg="white").pack()

        self.city_box=ttk.Combobox(self.root,state="readonly")
        self.city_box["values"]=list(self.weather_dict.keys())
        self.city_box.current(0)
        self.city_box.pack(pady=8)

        ttk.Button(self.root,text="☀️ 查询天气",command=self.get_weather).pack(pady=15)
        self.res=tk.Label(self.root,text="等待查询...",bg="#383838",fg="#cccccc",width=40,height=5,relief="solid")
        self.res.pack()

    def get_weather(self):
        city=self.city_box.get()
        condition=random.choice(self.weather_dict[city])
        temp=random.randint(12,32)
        wind=random.choice(["微风","东风","南风","无风"])
        info=f"📍城市：{city}\n🌡️气温：{temp}℃\n☁️天气：{condition}\n💨风向：{wind}"
        self.res.config(text=info,fg="#a8e6cf")

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