Mundo em Python

Calcular Logística

from tkinter import *

root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Logística") # Título
titulo = Label(
text="Calcular Logística",
font=("Arial", 35, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.18, rely=0.05) # Textos
texto_sub1 = Label(
text="Distância (km):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.33, rely=0.2) texto_sub2 = Label(
text="Velocidade média (km/h):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.18, rely=0.33) texto_sub3 = Label(
text="Número de soldados:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub3.place(relx=0.26, rely=0.45) texto_sub4 = Label(
text="Consumo por soldado (unidades por hora):",
font=("Arial", 15, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub4.place(relx=0.05, rely=0.55) # Entradas
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.21, relwidth=0.29)
Distância_entrada.focus() Velocidade_média = StringVar()
Velocidade_média_entrada = Entry(textvariable=Velocidade_média,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Velocidade_média_entrada.place(relx=0.67, rely=0.34, relwidth=0.29) Número_soldados = StringVar()
Número_soldados_entrada = Entry(textvariable=Número_soldados,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Número_soldados_entrada.place(relx=0.67, rely=0.46, relwidth=0.29) Consumo_por_soldado = StringVar()
Consumo_por_soldado_entrada = Entry(textvariable=Consumo_por_soldado,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Consumo_por_soldado_entrada.place(relx=0.67, rely=0.56, relwidth=0.29) # Funções
def limpar():
Consumo_por_soldado_entrada.delete(0, END)
Número_soldados_entrada.delete(0, END)
Velocidade_média_entrada.delete(0, END)
Distância_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
consumo_por_hora = float(Consumo_por_soldado.get())
soldados = int(Número_soldados.get())
velocidade = float(Velocidade_média.get())
distancia = float(Distância.get()) if velocidade <= 0:
resultado_texto.config(text="A velocidade deve ser maior que zero.")
return

# Cálculos
tempo_viagem = distancia / velocidade
consumo_total = consumo_por_hora * soldados * tempo_viagem mensagem = (
f"Distância total: {distancia:.2f} km\n"
f"Tempo estimado de viagem: {tempo_viagem:.2f} horas\n"
f"Total de soldados: {soldados}\n"
f"Consumo total de suprimentos: {consumo_total:.2f} unidades"
) 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()
0