from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Preço Total do Estacionamento")
titulo = Label(text="Preço Total do Estacionamento",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(text="Número de horas:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.15, rely=0.3)
texto_sub2 = Label(text="Número de minutos:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.13, rely=0.47)
horas = StringVar()
horas_entrada = Entry(textvariable=horas,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
horas_entrada.place(relx=0.55, rely=0.31, relwidth=0.35)
minutos = StringVar()
minutos_entrada = Entry(textvariable=minutos,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
minutos_entrada.place(relx=0.55, rely=0.48, relwidth=0.35)
def limpar():
minutos_entrada.delete(0, END)
horas_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
tempo_horas = int(horas.get())
tempo_minutos = int(minutos.get())
PRECO_POR_HORA = 5.0
total_horas = tempo_horas + (tempo_minutos / 60)
valor = round(total_horas * PRECO_POR_HORA, 2)
mensagem = f"Valor a pagar: {valor} €"
resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Valor digitado é inválido!! ")
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, 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.65, 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.65, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()