diff --git a/app/__pycache__/game.cpython-313.pyc b/app/__pycache__/game.cpython-313.pyc index 2d11aee..f832a28 100644 Binary files a/app/__pycache__/game.cpython-313.pyc and b/app/__pycache__/game.cpython-313.pyc differ diff --git a/app/__pycache__/panel_izquierdo.cpython-313.pyc b/app/__pycache__/panel_izquierdo.cpython-313.pyc index 0d421d6..82fcb26 100644 Binary files a/app/__pycache__/panel_izquierdo.cpython-313.pyc and b/app/__pycache__/panel_izquierdo.cpython-313.pyc differ diff --git a/app/__pycache__/pomodoro.cpython-313.pyc b/app/__pycache__/pomodoro.cpython-313.pyc index f846e30..c7848e9 100644 Binary files a/app/__pycache__/pomodoro.cpython-313.pyc and b/app/__pycache__/pomodoro.cpython-313.pyc differ diff --git a/app/panel_izquierdo.py b/app/panel_izquierdo.py index 92f7025..97609b9 100644 --- a/app/panel_izquierdo.py +++ b/app/panel_izquierdo.py @@ -1,15 +1,19 @@ import tkinter as tk import threading +import requests +from PIL import Image, ImageTk +from io import BytesIO from app import scraping class PanelIzquierdo: def __init__(self, frame, text_widget): - # Asociar el frame del panel izquierdo + # Configuración del panel self.frame = frame - self.frame.configure(bg="lightblue", width=200) + self.frame.configure(bg="lightblue", width=300) self.frame.grid_propagate(False) self.frame.columnconfigure(0, weight=1) - + + # Botón para iniciar scraping (ya existente) boton_scrapping = tk.Button( frame, text="Iniciar Scrapping", @@ -18,4 +22,58 @@ class PanelIzquierdo: args=("https://www.amazon.es/", text_widget) ).start() ) - boton_scrapping.pack(pady=5) \ No newline at end of file + boton_scrapping.pack(pady=5) + + # Clima - Título + self.weather_title = tk.Label( + frame, text="Clima Actual", bg="lightblue", font=("Helvetica", 14, "bold"), fg="navy" + ) + self.weather_title.pack(pady=10) + + # Clima - Ícono + self.weather_icon = tk.Label(frame, bg="lightblue") + self.weather_icon.pack() + + # Clima - Información + self.weather_label = tk.Label( + frame, text="Cargando clima...", bg="lightblue", font=("Helvetica", 10, "bold"), fg="black" + ) + self.weather_label.pack(pady=5) + + # Variables para el clima + self.api_key = '2f79c6f35c48e876bceae7fa7f4f4735' + self.city = 'Javea' # Cambia por la ciudad que desees + self.update_weather() + + def update_weather(self): + """Actualiza la información del clima utilizando un hilo.""" + def fetch_weather(): + try: + url = f'http://api.openweathermap.org/data/2.5/weather?q={self.city}&appid={self.api_key}&units=metric&lang=es' + response = requests.get(url) + response.raise_for_status() + data = response.json() + + # Información del clima + temp = data['main']['temp'] + weather = data['weather'][0]['description'] + icon_code = data['weather'][0]['icon'] + + # Actualiza el texto del clima + self.weather_label.config( + text=f"{self.city}:\n{temp}°C, {weather.capitalize()}" + ) + + # Descarga y muestra el ícono del clima + icon_url = f"http://openweathermap.org/img/wn/{icon_code}@2x.png" + icon_response = requests.get(icon_url) + icon_image = Image.open(BytesIO(icon_response.content)) + icon_photo = ImageTk.PhotoImage(icon_image) + self.weather_icon.config(image=icon_photo) + self.weather_icon.image = icon_photo # Referencia para evitar que se elimine + + except Exception as e: + self.weather_label.config(text=f"Error al obtener el clima.") + print(f"Error al obtener el clima: {e}") + + threading.Thread(target=fetch_weather, daemon=True).start() diff --git a/main.py b/main.py index 8a9f15f..8325f8f 100644 --- a/main.py +++ b/main.py @@ -64,7 +64,7 @@ menu_bar.add_cascade(label="Ayuda", menu=help_menu) root.config(menu=menu_bar) # Crear los frames laterales y el central -frame_izquierdo = tk.Frame(root, bg="lightblue", width=200) +frame_izquierdo = tk.Frame(root, bg="lightblue", width=300) frame_central = tk.Frame(root, bg="white") frame_derecho = tk.Frame(root, bg="lightgreen", width=200)