Mundo em Python

Calcular a Pegada Transporte

from tkinter import *

root = Tk()
root.geometry("700x650")
root.resizable(0, 0)
root.config(bg="#103030")
def calcular_pegada_transporte(distancia_carro, distancia_aviao):
emissao_carro = 0.2 # kg CO2 por km
emissao_aviao = 0.115 # kg CO2 por km
total_carro = distancia_carro * emissao_carro
total_aviao = distancia_aviao * emissao_aviao
total_transporte = total_carro + total_aviao
return total_transporte
def calcular_pegada_energia(consumo_energia):
emissao_energia = 0.4 # kg CO2 por kWh
total_energia = consumo_energia * emissao_energia
return total_energia
def calcular_pegada_alimentacao(consumo_carne, consumo_vegetais):
emissao_carne = 27 # kg CO2 por kg de carne
emissao_vegetais = 2 # kg CO2 por kg de vegetais
total_carne = consumo_carne * emissao_carne
total_vegetais = consumo_vegetais * emissao_vegetais
total_alimentacao = total_carne + total_vegetais
return total_alimentacao
def calcular_pegada_residuos(porcentagem_reciclado):
emissao_residuos_nao_reciclados = 0.5 # kg CO2 por kg de resíduos não reciclados
total_residuos = 1 - porcentagem_reciclado # porcentagem de resíduos não reciclados
total_residuos_emissao = total_residuos * emissao_residuos_nao_reciclados
return total_residuos_emissao
root.title("Calcular a Pegada Transporte")
titulo = Label(text="Calcular a Pegada Transporte",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05) texto_sub1 = Label(text="Distância percorrida de carro (km) :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.15) texto_sub2 = Label(text="Distância percorrida de avião (km):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.25) texto_sub3 = Label(text="Consumo de energia elétrica (kWh):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.05, rely=0.35) texto_sub4 = Label(text="Quantidade de carne consumida (kg):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub4.place(relx=0.05, rely=0.45) texto_sub5 = Label(text="Quantidade de vegetais consumidos (kg):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub5.place(relx=0.05, rely=0.55) texto_sub6 = Label(text="Percentual de resíduos reciclados (0 a 1):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub6.place(relx=0.05, rely=0.65) percorrer_carro = StringVar()
percorrer_carro_entrada = Entry(textvariable=percorrer_carro,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
percorrer_carro_entrada.place(relx=0.75, rely=0.16, relwidth=0.2) percorrer_avião = StringVar()
percorrer_avião_entrada = Entry(textvariable=percorrer_avião,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
percorrer_avião_entrada.place(relx=0.75, rely=0.26, relwidth=0.2) energia_elétrica = StringVar()
energia_elétrica_entrada = Entry(textvariable=energia_elétrica,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
energia_elétrica_entrada.place(relx=0.75, rely=0.36, relwidth=0.2) carne_consumida = StringVar()
carne_consumida_entrada = Entry(textvariable=carne_consumida,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
carne_consumida_entrada.place(relx=0.75, rely=0.46, relwidth=0.2) vegetais_consumidos = StringVar()
vegetais_consumidos_entrada = Entry(textvariable=vegetais_consumidos,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
vegetais_consumidos_entrada.place(relx=0.75, rely=0.56, relwidth=0.2) resíduos_reciclados = StringVar()
resíduos_reciclados_entrada = Entry(textvariable=resíduos_reciclados,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
resíduos_reciclados_entrada.place(relx=0.75, rely=0.66, relwidth=0.2)
def limpar():
resíduos_reciclados_entrada.delete(0, END)
vegetais_consumidos_entrada.delete(0, END)
carne_consumida_entrada.delete(0, END)
energia_elétrica_entrada.delete(0, END)
percorrer_carro_entrada.delete(0, END)
percorrer_avião_entrada.delete(0, END)
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.config(state=DISABLED)
def app():
try:
distancia_carro = float(percorrer_carro.get())
distancia_aviao = float(percorrer_avião.get())
consumo_energia = float(energia_elétrica.get())
consumo_carne = float(carne_consumida.get())
consumo_vegetais = float(vegetais_consumidos.get())
porcentagem_reciclado = float(resíduos_reciclados.get())
if porcentagem_reciclado <= 1: total_transporte = calcular_pegada_transporte(distancia_carro, distancia_aviao)
total_energia = calcular_pegada_energia(consumo_energia)
total_alimentacao = calcular_pegada_alimentacao(consumo_carne, consumo_vegetais)
total_residuos = calcular_pegada_residuos(porcentagem_reciclado)
pegada_total = total_transporte + total_energia + total_alimentacao + total_residuos mensagem = f"Total de CO2 emitido pelo transporte: {total_transporte:.2f} kg CO2\n" \
f"Total de CO2 emitido pelo consumo de energia: {total_energia:.2f} kg CO2\n" \
f"Total de CO2 emitido pela alimentação: {total_alimentacao:.2f} kg CO2\n" \
f"Total de CO2 emitido pelos resíduos: {total_residuos:.2f} kg CO2\n" \
f"Total de CO2 emitido: {pegada_total:.2f} kg CO2"

resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.insert(END, mensagem)
resultado_texto.config(state=DISABLED)
else:
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.insert(END, "O Percentual de resíduos reciclados não deve estar entre 0 a 1.")
resultado_texto.config(state=DISABLED) except ValueError:
resultado_texto.config(state=NORMAL)
resultado_texto.delete(1.0, END)
resultado_texto.insert(END, "Por favor, insira todos os valores corretamente.")
resultado_texto.config(state=DISABLED)
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.73, relwidth=0.25, relheight=0.05) 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.73, relwidth=0.25, relheight=0.05) 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.73, relwidth=0.25, relheight=0.05) resultado_frame = Frame(root)
resultado_frame.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15) scrollbar = Scrollbar(resultado_frame)
scrollbar.pack(side=RIGHT, fill=Y) resultado_texto = Text(resultado_frame, wrap=WORD, font=("Arial", 12, "bold"), bg="#cfe2f3", height=6,
yscrollcommand=scrollbar.set)
resultado_texto.pack(side=LEFT, fill=BOTH, expand=True) scrollbar.config(command=resultado_texto.yview) root.mainloop()
0