Mundo em Python

Calcular Custo Transporte (usando tkinter )

from tkinter import *
root = Tk()
root.geometry("450x550")
root.resizable(0, 0)
root.config(bg="#1086a3")
root.title("Calcular Custo Transporte")
titulo = Label(text="Calcular Custo Transporte ",
font=("Arial", "20", "bold"),bg="#1086a3",fg="#d9ead3")
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(text="Distância Percorrida(km):",
font=("Arial", "15", "bold"),bg="#1086a3",fg="#d9ead3")
texto_sub1.place(relx=0.05, rely=0.2)
texto_sub2 = Label(text="Gasto por km/h:",
font=("Arial", "15", "bold"),bg="#1086a3",fg="#d9ead3")
texto_sub2.place(relx=0.1, rely=0.3)
texto_sub3 = Label(text="Custo do Combustível:",
font=("Arial", "15", "bold"),bg="#1086a3",fg="#d9ead3")
texto_sub3.place(relx=0.07, rely=0.4) texto_sub4 = Label(text="Custo das Portagens:",
font=("Arial", "15", "bold"),bg="#1086a3",fg="#d9ead3")
texto_sub4.place(relx=0.07, rely=0.5)
texto_sub5 = Label(text="Receita do Transporte:",
font=("Arial", "15", "bold"),bg="#1086a3",fg="#d9ead3")
texto_sub5.place(relx=0.07, rely=0.6)
distancia = DoubleVar()
distancia_entrada = Entry(textvariable=distancia,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
distancia_entrada.place(relx=0.6, rely=0.2, relwidth=0.35) Gasto_km_h = DoubleVar()
Gastokm_entrada = Entry(textvariable=Gasto_km_h, font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Gastokm_entrada.place(relx=0.6, rely=0.3, relwidth=0.35) Custo_Combustível = DoubleVar()
Custo_Combustível_entrada = Entry(textvariable=Custo_Combustível,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Custo_Combustível_entrada.place(relx=0.6, rely=0.4, relwidth=0.35)
Custo_Portagens = DoubleVar()
Custo_Portagens_entrada = Entry(textvariable=Custo_Portagens,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Custo_Portagens_entrada.place(relx=0.6, rely=0.5, relwidth=0.35) Receita_transporte = DoubleVar()
Receita_transporte_entrada = Entry(textvariable=Receita_transporte,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Receita_transporte_entrada.place(relx=0.6, rely=0.6, relwidth=0.35) def app():
receitas_trans = Receita_transporte.get()
cust_port = Custo_Portagens.get()
cust_comb = Custo_Combustível.get()
d = distancia.get()
gasto_km_h=Gasto_km_h.get()
custo_variavel = gasto_km_h*d*cust_comb
custo_total = cust_port+custo_variavel
custo_totalarr = round(custo_total,2)
Lucro = receitas_trans - custo_total
mesagem1 = f"O custo total é de {custo_totalarr}."
if Lucro == 0:
mesagem2 = 'Não tem lucro nem tem prejúzo.'
resultado_texto["fg"] = "blue"
elif Lucro >0:
mesagem2 = f'O lucro é de {Lucro}.'
resultado_texto["fg"] = "green"
else:
mesagem2 = f'O prejúzo é de {Lucro*(-1)}.'
resultado_texto["fg"] = "red"

mensagemfinal = f"{mesagem1}\n{mesagem2}"
resultado.set(mensagemfinal) def limpar():
Receita_transporte_entrada.delete(0, END)
Custo_Portagens_entrada.delete(0, END)
Custo_Combustível_entrada.delete(0, END)
Gastokm_entrada.delete(0, END)
distancia_entrada.delete(0, END)
resultado.set("") #
but1 = Button(text="Verificar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.7, 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.35, rely=0.7, 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.65, rely=0.7, relwidth=0.25, relheight=0.1) resultado = StringVar()
resultado_texto = Label(textvariable=resultado,
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.83, relwidth=0.9,relheight=0.15)
root.mainloop()
0