Antes de ejecutar el c贸digo, debes instalar las bibliotecas tkinter, PIL, schedule, time y datetime, abriendo la consola del sistema
-pip install Pillow
-pip install schedule
En Windows:
tkinter generalmente se instala autom谩ticamente con Python. Si no lo tienes, descarga e instala la 煤ltima versi贸n de Python desde python.org, que incluye tkinter.
time y datetime
Las bibliotecas time y datetime son bibliotecas est谩ndar de Python y no requieren instalaci贸n adicional. Vienen incluidas con la instalaci贸n de Python.
Comprobaci贸n de la instalaci贸n
Para asegurarte de que todas las bibliotecas est谩n instaladas correctamente, puedes crear un peque帽o script de prueba para importarlas:
import tkinter as tk
from PIL import Image, ImageTk
import schedule
import time
import datetime
print("Todas las bibliotecas se han instalado correctamente.")
Instalaci贸n de Python y pip
Si a煤n no tienes Python o pip instalados, sigue estas instrucciones:
En Windows y macOS:
Descarga el instalador de Python desde python.org.
Ejecuta el instalador y sigue las instrucciones en pantalla.
Aseg煤rate de marcar la opci贸n "Add Python to PATH" durante la instalaci贸n
SCRIPT PARA MOSTRAR IMAGEN EN PANTALLA CON UNA HORA DETERMINADA EN AM O PM Y CERRAR IMAGEN AUTOMATICAMENTE
import tkinter as tk
from PIL import Image, ImageTk
import schedule
import time
import datetime
def mostrar_imagen_sobrepuesta(ruta_imagen, tiempo_cierre=10000): # tiempo_cierre en milisegundos
print(f"Mostrando imagen: {ruta_imagen}")
ventana = tk.Toplevel()
ventana.overrideredirect(True)
ventana.attributes("-topmost", True)
ventana.geometry("+0+0")
imagen = Image.open(ruta_imagen)
imagen = imagen.resize((ventana.winfo_screenwidth(),
ventana.winfo_screenheight()))
imagen_tk = ImageTk.PhotoImage(imagen)
etiqueta = tk.Label(ventana, image=imagen_tk)
etiqueta.pack()
ventana.update() # Actualizar la ventana para mostrar la imagen
def cerrar_ventana(event=None):
ventana.destroy()
etiqueta.bind("<Button-1>", cerrar_ventana)
# Cerrar autom谩ticamente la ventana despu茅s de 'tiempo_cierre' milisegundos
ventana.after(tiempo_cierre, cerrar_ventana)
ventana.mainloop() # Iniciar el bucle principal de la ventana
def programar_tarea_mostrar_imagen(ruta_imagen, hora_str, tiempo_cierre=10000):
# Convertir la hora en formato de 12 horas con A.M./P.M. a formato de 12 horas
hora = datetime.datetime.strptime(hora_str, "%I:%M %p").time()
hora_str_format = hora.strftime("%H:%M")
schedule.every().day.at(hora_str_format).do(mostrar_imagen_sobrepuesta, ruta_imagen, tiempo_cierre)
# Programar la tarea para mostrar la imagen
ruta_imagen = "E:/python/salud.jpg" # Ruta de la imagen
hora_str = "10:58 AM" # # Hora en formato HH:MM AM/PM
tiempo_cierre = 10000 # Tiempo en milisegundos para cerrar la imagen autom谩ticamente (por ejemplo, 10 segundos)
programar_tarea_mostrar_imagen(ruta_imagen, hora_str, tiempo_cierre)
while True:
schedule.run_pending()
time.sleep(1)