from tkinter import *
root = Tk()
root.geometry("600x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Verificar limite de velocidade")
titulo = Label(text="Verificar limite de velocidade",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
label_distancia = Label(text="Distância percorrida (em km):",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
label_distancia.place(relx=0.05, rely=0.32)
label_tempo = Label(text="Tempo gasto (em horas):",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
label_tempo.place(relx=0.13, rely=0.5)
Distância = StringVar()
Distância_entrada = Entry(textvariable=Distância,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Distância_entrada.place(relx=0.67, rely=0.33, relwidth=0.25)
Distância_entrada.focus()
tempo = StringVar()
tempo_entrada = Entry(textvariable=tempo,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
tempo_entrada.place(relx=0.67, rely=0.51, relwidth=0.25)
def limpar():
tempo_entrada.delete(0, END)
Distância_entrada.delete(0, END)
resultado_texto.config(text="", bg="#cfe2f3")
def app():
try:
t = float(tempo.get())
d = float(Distância.get())
if t <= 0 or d <= 0:
raise ValueError("Tempo e distância devem ser positivos.")
velocidade_media = d / t
limite = 80
mensagem = f"Velocidade média: {velocidade_media:.2f} km/h\n"
if velocidade_media > limite:
mensagem += "Ultrapassou o limite de velocidade!\nReduza a velocidade."
resultado_texto.config(bg="red", text=mensagem)
else:
mensagem += "Está dentro do limite de velocidade.\nBoa viagem!"
resultado_texto.config(bg="green", text=mensagem)
except ValueError:
resultado_texto.config(bg="#cfe2f3", text="Por favor, insira valores numéricos válidos.")
but1 = Button(text="Verificar", 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()