from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Impostos Combustível")
titulo = Label(text="Calcular Impostos Combustível",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(text="Preço por litro :",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.32)
Preço_por_litro = StringVar()
Preço_por_litro_entrada = Entry(textvariable=Preço_por_litro,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Preço_por_litro_entrada.place(relx=0.5, rely=0.33, relwidth=0.35)
var = StringVar()
dropDownList = ["Gasolina", "Gasóleo"]
dropdown = OptionMenu(root, var, *dropDownList)
var.set(dropDownList[0])
dropdown.place(relx=0.35, rely=0.45, relwidth=0.4)
dropdown.config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 15, "bold"))
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 15, "bold"))
def limpar():
Preço_por_litro_entrada.delete(0, END)
resultado_texto.delete('1.0', END)
def app():
try:
preco_total = float(Preço_por_litro.get().replace(",", "."))
tipo = var.get().lower()
componentes_isp = {
'gasolina': {
'isp_total': 0.65,
'taxa_carbono': 0.084
},
'gasóleo': {
'isp_total': 0.50,
'taxa_carbono': 0.088
}
}
if tipo not in componentes_isp:
raise ValueError("Tipo inválido. Use 'Gasolina' ou 'Gasóleo'.")
isp_total = componentes_isp[tipo]['isp_total']
taxa_carbono = componentes_isp[tipo]['taxa_carbono']
isp_sem_carbono = isp_total - taxa_carbono
preco_sem_iva = preco_total / 1.23
iva = preco_total - preco_sem_iva
preco_base = preco_sem_iva - isp_total
mensagem = f"""
Preço Total: €{round(preco_total, 3)}
IVA (23%): €{round(iva, 3)}
ISP Total: €{round(isp_total, 3)}
- ISP sem carbono: €{round(isp_sem_carbono, 3)}
- Taxa carbono: €{round(taxa_carbono, 3)}
Preço base (sem ISP e IVA): €{round(preco_base, 3)}
"""
resultado_texto.delete('1.0', END)
resultado_texto.insert(END, mensagem.strip())
except ValueError as e:
resultado_texto.delete('1.0', END)
resultado_texto.insert(END, f"Erro: {str(e)}")
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_frame = Frame(root, bg="#cfe2f3")
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, font=("Arial", 12, "bold"),
bg="#cfe2f3", wrap=WORD, yscrollcommand=scrollbar.set)
resultado_texto.pack(fill=BOTH, expand=True)
scrollbar.config(command=resultado_texto.yview)
root.mainloop()