from tkinter import *
root = Tk()
root.geometry("800x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Consumo de Combustível no navio")
titulo = Label(
text="Consumo de Combustível no navio", font=("Arial", 28, "bold"),
bg="#103030", fg="#49e3e3"
)
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(
text="Velocidade do barco (em nós):", font=("Arial", 18, "bold"),
bg="#103030", fg="#49e3e3"
)
texto_sub1.place(relx=0.24, rely=0.25)
texto_sub2 = Label(
text="Distância da viagem (em milhas náuticas):", font=("Arial", 18, "bold"),
bg="#103030", fg="#49e3e3"
)
texto_sub2.place(relx=0.05, rely=0.4)
texto_sub3 = Label(
text="Consumo médio do motor (em L/h):", font=("Arial", 18, "bold"),
bg="#103030", fg="#49e3e3"
)
texto_sub3.place(relx=0.15, rely=0.5)
Velocidade_barco = StringVar()
Velocidade_barco_entrada = Entry(
textvariable=Velocidade_barco, font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center'
)
Velocidade_barco_entrada.place(relx=0.7, rely=0.27, relwidth=0.25)
Velocidade_barco_entrada.focus()
Distância_viagem = StringVar()
Distância_viagem_entrada = Entry(
textvariable=Distância_viagem, font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center'
)
Distância_viagem_entrada.place(relx=0.7, rely=0.41, relwidth=0.25)
Consumo_médio = StringVar()
Consumo_médio_entrada = Entry(
textvariable=Consumo_médio, font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center'
)
Consumo_médio_entrada.place(relx=0.7, rely=0.51, relwidth=0.25)
def limpar():
Distância_viagem_entrada.delete(0, END)
Velocidade_barco_entrada.delete(0, END)
Consumo_médio_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
distancia = float(Distância_viagem.get())
velocidade = float(Velocidade_barco.get())
consumo_medio = float(Consumo_médio.get())
tempo_horas = distancia / velocidade
combustivel_gasto = tempo_horas * consumo_medio
resultado_texto.config(
text=(
f"Tempo estimado de viagem: {tempo_horas:.2f} horas\n"
f"Combustível estimado: {combustivel_gasto:.2f} litros\n"
f"Boa navegação! ⛵"
)
)
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()