from tkinter import *
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Velocidade Média")
titulo = Label(text="Velocidade Média",
font=("Arial", "33", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(text="Distância Total Percorrida(em km):",
font=("Arial", "13", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25)
texto_sub2 = Label(text="Tempo Total Gasto(em horas) :",
font=("Arial", "13", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.08, rely=0.4)
distância_total = StringVar()
distância_total_entrada = Entry(textvariable=distância_total,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
distância_total_entrada.place(relx=0.6, rely=0.25, relwidth=0.28)
distância_total_entrada.focus()
Tempo_Total_Gasto = StringVar()
Tempo_Total_Gasto_entrada = Entry(textvariable=Tempo_Total_Gasto,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Tempo_Total_Gasto_entrada.place(relx=0.6, rely=0.4, relwidth=0.28)
def limpar():
Tempo_Total_Gasto_entrada.delete(0, END)
distância_total_entrada.delete(0, END)
resultado_texto.config(text="")
def app(event=None):
try:
tempo_total = float(Tempo_Total_Gasto.get())
d_total = float(distância_total.get())
velocidade_média = d_total / tempo_total
if velocidade_média <=50:
mensagem = "A velocidade média não foi ultrapassada."
else:
mensagem = f"A velocidade média foi ultrapassada.\n" \
f"Diferença: {round(velocidade_média-50,2)} "
resultado_texto.config(text=f"Velocidade Média: {velocidade_média:.2f} km/hora\n {mensagem}")
except ValueError:
resultado_texto.config(text="Valor digitado errado!!")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.53, 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.53, 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.53, relwidth=0.25, relheight=0.1)
resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.68, relwidth=0.9, relheight=0.3)
root.bind('<Return>', app)
root.mainloop()