48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import tkinter as tk
|
|
import threading
|
|
import requests
|
|
import time
|
|
|
|
class WeatherWidget:
|
|
def __init__(self, parent, api_key):
|
|
"""
|
|
Crea un widget para mostrar información meteorológica usando OpenWeatherMap.
|
|
|
|
Args:
|
|
parent (tk.Frame): Frame donde se colocará el widget.
|
|
api_key (str): Clave de la API de OpenWeatherMap.
|
|
"""
|
|
self.parent = parent
|
|
self.api_key = api_key
|
|
|
|
# Configurar interfaz del widget
|
|
self.frame = tk.Frame(self.parent, bg="white", bd=2, relief="groove")
|
|
self.frame.pack(padx=10, pady=10, fill="x", anchor="n")
|
|
|
|
self.header_label = tk.Label(self.frame, text="Weather in ...", font=("Helvetica", 14, "bold"), bg="white")
|
|
self.header_label.pack(pady=5)
|
|
|
|
self.temp_label = tk.Label(self.frame, text="--°C", font=("Helvetica", 28, "bold"), bg="white")
|
|
self.temp_label.pack()
|
|
|
|
self.details_label = tk.Label(self.frame, text="", font=("Helvetica", 12), bg="white", justify="left")
|
|
self.details_label.pack(pady=5)
|
|
|
|
# Iniciar actualización automática del clima
|
|
self.start_weather_updates()
|
|
|
|
def get_weather(self, lat, lon):
|
|
"""
|
|
Obtiene la temperatura, viento y calidad del aire desde OpenWeatherMap.
|
|
|
|
Args:
|
|
lat (float): Latitud.
|
|
lon (float): Longitud.
|
|
"""
|
|
# Llamada a la API de OpenWeatherMap para obtener datos meteorológicos
|
|
pass
|
|
|
|
def start_weather_updates(self):
|
|
"""Inicia un hilo que actualiza la información meteorológica cada 60 segundos."""
|
|
threading.Thread(target=self.update_weather, daemon=True).start()
|