from tkinter import *
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Índice de Preços e Cálculo da Taxa de Inflação")
titulo = Label(text="Índice de Preços e Cálculo da Taxa de Inflação",
font=("Arial", "16", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="Custo Base:",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.2)
texto_sub2 = Label(text="Custo Actual:",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.2, rely=0.35)
texto_sub3 = Label(text="IPC Anterior:",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.2, rely=0.47)
Custo_Base = StringVar()
Custo_Base_entrada = Entry(textvariable=Custo_Base,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Custo_Base_entrada.place(relx=0.55, rely=0.21, relwidth=0.35)
IPC_Anterior = StringVar()
IPC_Anterior_entrada = Entry(textvariable=IPC_Anterior,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
IPC_Anterior_entrada.place(relx=0.55, rely=0.48, relwidth=0.35)
Custo_actual = StringVar()
Custo_actual_entrada = Entry(textvariable=Custo_actual,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Custo_actual_entrada.place(relx=0.55, rely=0.36, relwidth=0.35)
def limpar():
Custo_Base_entrada.delete(0, END)
Custo_actual_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
base=float(Custo_Base.get())
actual = float(Custo_actual.get())
IPCanterior = float(IPC_Anterior.get())
ipc_atual = (actual / base) * 100
inflacao = ((ipc_atual - IPCanterior) / IPCanterior) * 100
resultado_texto.config(text=f"IPC ACTUAL: {ipc_atual}\n Inflação: {inflacao}")
except ValueError:
resultado_texto.config(text="Valor inválido digitado.")
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_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()