from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular o IMI")
titulo = Label(text="Calcular o IMI",
font=("Arial", "35", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
sub1 = Label(text="Taxa de IMI (entre 0,3% e 0,8%) ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
sub1.place(relx=0.08, rely=0.25)
taxa = StringVar()
taxa_entrada = Entry(textvariable=taxa,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
taxa_entrada.place(relx=0.3, rely=0.35, relwidth=0.45)
taxa_entrada.focus()
sub2 = Label(text="Valor do Património (em €) ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
sub2.place(relx=0.2, rely=0.4)
Valor_Patrimonio = StringVar()
Valor_Patrimonio_entrada = Entry(textvariable=Valor_Patrimonio,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Valor_Patrimonio_entrada.place(relx=0.3, rely=0.5, relwidth=0.45)
def limpar():
taxa_entrada.delete(0,END)
Valor_Patrimonio_entrada.delete(0,END)
resultado_texto.config(text="")
def app():
try:
t = float(taxa.get())
vp = float(Valor_Patrimonio.get())
if 0.3 <= t <= 0.8:
tp = t / 100
imi = tp * vp
mensagem = f"Valor do IMI: {round(imi, 2)} €"
else:
mensagem = "A taxa de IMI deve estar entre 0,3% e 0,8%."
except ValueError:
mensagem = "Erro de digitação! Certifique-se de inserir números válidos."
resultado_texto.config(text=mensagem)
but1 = Button(text="Mostrar", 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(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()