from tkinter import *
root = Tk()
root.geometry("700x600")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular IUC")
titulo = Label(text="Calcular IUC",
font=("Arial", "40", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.18, rely=0.05)
texto_sub1 = Label(text="Cilindrada do carro (em cc):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.18, rely=0.25)
texto_sub2 = Label(text="Emissões de CO₂ do carro (em g/km):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.35)
texto_sub3 = Label(text="Ano de matrícula do carro:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.23, rely=0.45)
Cilindrada = StringVar()
Cilindrada_entrada = Entry(textvariable=Cilindrada,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Cilindrada_entrada.place(relx=0.7, rely=0.26, relwidth=0.2)
Emissões_CO = StringVar()
Emissões_CO_entrada = Entry(textvariable=Emissões_CO,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Emissões_CO_entrada.place(relx=0.7, rely=0.36, relwidth=0.2)
Ano_matrícula = StringVar()
Ano_matrícula_entrada = Entry(textvariable=Ano_matrícula,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Ano_matrícula_entrada.place(relx=0.7, rely=0.46, relwidth=0.2)
def limpar():
Ano_matrícula_entrada.delete(0, END)
Emissões_CO_entrada.delete(0, END)
Cilindrada_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
cilindrada = int(Cilindrada.get())
emissao_co2 = int(Emissões_CO.get())
ano_matricula = int(Ano_matrícula.get())
isv_cilindrada = max(0, (cilindrada - 1000) * 2)
isv_emissao = max(0, (emissao_co2 - 95) * 10)
isv_total = isv_cilindrada + isv_emissao
if ano_matricula >= 2007:
iuc_base = 50
iuc_cilindrada = max(0, (cilindrada - 1000) * 0.50)
iuc_emissao = max(0, (emissao_co2 - 120) * 1)
else:
iuc_base = 30
iuc_cilindrada = max(0, (cilindrada - 1000) * 0.25)
iuc_emissao = max(0, (emissao_co2 - 140) * 0.5)
iuc_total = iuc_base + iuc_cilindrada + iuc_emissao
resultado_texto.config(
text=f"ISV: €{isv_total:.2f}\nIUC: €{iuc_total:.2f}")
except ValueError:
resultado_texto.config(text="Por favor, insira valores válidos.")
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.55, 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.55, 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.55, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
root.mainloop()