from tkinter import *
root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Interseção entre dois veículos")
titulo = Label(
text="Interseção entre dois veículos",font=("Arial", 28, "bold"),bg="#103030",fg="#49e3e3")
titulo.place(relx=0.13, rely=0.05)
texto_sub1 = Label(
text="Distância (em km):",font=("Arial", 18, "bold"),bg="#103030",fg="#49e3e3")
texto_sub1.place(relx=0.1, rely=0.25)
texto_sub2 = Label(
text="Velocidade do Veículo 1 (em km\h):",font=("Arial", 15, "bold"),bg="#103030",fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.36)
texto_sub3 = Label(
text="Velocidade do Veículo 2 (em km\h):",font=("Arial", 15, "bold"),bg="#103030",fg="#49e3e3")
texto_sub3.place(relx=0.05, 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.55, rely=0.26, relwidth=0.35)
Distância_entrada.focus()
Veículo1 = StringVar()
Veículo1_entrada = Entry(
textvariable=Veículo1,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Veículo1_entrada.place(relx=0.55, rely=0.37, relwidth=0.35)
Veículo2 = StringVar()
Veículo2_entrada = Entry(
textvariable=Veículo2,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Veículo2_entrada.place(relx=0.55, rely=0.51, relwidth=0.35)
def limpar():
Veículo2_entrada.delete(0,END)
Veículo1_entrada.delete(0,END)
resultado_texto.config(text="")
def app():
try:
v2 = float(Veículo2.get())
v1 = float(Veículo1.get())
distancia =float(Distância.get())
tempo = distancia / (v1 + v2)
posicao = v1 * tempo
tempo = distancia / (v1 + v2)
# print("")
# print("E a", round(distancia - posicao, 2), "km de Lisboa")
mensagem = f"Tempo até se encontrarem: {round(tempo, 2)}horas\n" \
f"Encontram-se a {round(posicao, 2)}km\n E a {round(distancia - posicao, 2)}"
resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Por favor, insira valores numéricos válidos.")
# Botões
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()
Comentários
Enviar um comentário