Mundo em Python

Converter Horas em Dias

from tkinter import *

root = Tk()
root.geometry("600x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Converter Horas em Dias") titulo = Label(text="Converter Horas em Dias",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05) texto_sub1 = Label(text="Horas:",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.25) Horas = StringVar()
Horas_entrada = Entry(textvariable=Horas,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Horas_entrada.place(relx=0.45, rely=0.26, relwidth=0.35) def limpar():
Horas.set("")
resultado_texto.config(text="", fg="black") def app():
try:
horas = float(Horas.get())
dias_totais = horas / 24
dias_int = int(horas // 24)
horas_restantes = horas % 24
mensagem = (
f"{horas} horas equivalem a {round(dias_totais, 2)} dias\n"
f"Ou {dias_int} dia(s) e {round(horas_restantes, 2)} hora(s)"
)
resultado_texto.config(text=mensagem, fg="black")
except ValueError:
resultado_texto.config(text=" Valor digitado inválido!", fg="red") but1 = Button(text="Converter", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.45, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.45, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.45, relwidth=0.25, relheight=0.1) resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3", justify="center", anchor="center")
resultado_texto.place(relx=0.05, rely=0.6, relwidth=0.9, relheight=0.28) root.mainloop()
0