hilo con la hora
This commit is contained in:
parent
3cc5c43dc4
commit
5ae8189e5e
|
@ -1,6 +1,25 @@
|
|||
import tkinter as tk
|
||||
from tkinter import Menu # Importar el widget Menu
|
||||
from tkinter import ttk # Importar el widget ttk
|
||||
import threading
|
||||
import time
|
||||
import datetime
|
||||
|
||||
def update_time(status_bar):
|
||||
"""Función que actualiza la hora y el día de la semana en un label"""
|
||||
while True:
|
||||
# Obtener la fecha y hora actual
|
||||
now = datetime.datetime.now()
|
||||
day_of_week = now.strftime("%A") # Día de la semana
|
||||
time_str = now.strftime("%H:%M:%S") # Hora en formato HH:MM:SS
|
||||
date_str = now.strftime("%Y-%m-%d") # Fecha en formato YYYY-MM-DD
|
||||
label_text = f"{day_of_week}, {date_str} - {time_str}"
|
||||
|
||||
# Actualizar el label (debemos usar `after` para asegurarnos que se actualice en el hilo principal de Tkinter)
|
||||
barra_estado.after(1000, status_bar.config, {"text": label_text})
|
||||
|
||||
# Espera 1 segundo antes de actualizar de nuevo
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
# Crear la ventana principal
|
||||
|
@ -83,5 +102,14 @@ for i in range(1, 6):
|
|||
label = ttk.Label(tab, text=f"Contenido de la Solapa {i}")
|
||||
label.pack(pady=10)
|
||||
|
||||
# Barra de estado
|
||||
barra_estado = tk.Label(root, text="Hilo fecha-hora", font=("Helvetica", 16), bd=1, fg="blue", relief="sunken", anchor="w")
|
||||
barra_estado.grid(row=1, column=0, columnspan=3, sticky="ew")
|
||||
|
||||
|
||||
update_thread = threading.Thread(target=update_time, args=(barra_estado,))
|
||||
update_thread.daemon = True # Hacemos el hilo un demonio para que termine con la app
|
||||
update_thread.start()
|
||||
|
||||
# Ejecución de la aplicación
|
||||
root.mainloop()
|
||||
|
|
Loading…
Reference in New Issue