from tkinter import *
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#085969")
root.title("Custo Total de Prestações")
titulo = Label(
text="Custo Total de Prestações",
font=("Arial", "28", "bold"),
bg="#085969",
fg="#67cce0"
)
titulo.place(relx=0.03, rely=0.05)
# Labels
texto_sub1 = Label(
text="Prestação:",
font=("Arial", "16", "bold"),
bg="#085969",
fg="#67cce0"
)
texto_sub1.place(relx=0.35, rely=0.26)
texto_sub2 = Label(
text="Número de Prestações:",
font=("Arial", "16", "bold"),
bg="#085969",
fg="#67cce0"
)
texto_sub2.place(relx=0.1, rely=0.4)
# Entry Widgets
Prestação = DoubleVar()
Prestação_entrada = Entry(
textvariable=Prestação,
font=("Arial", "12", "bold"),
bg="white",
fg="blue",
justify='center'
)
Prestação_entrada.place(relx=0.6, rely=0.26, relwidth=0.25)
Número_Prestação = IntVar()
Número_Prestação_entrada = Entry(
textvariable=Número_Prestação,
font=("Arial", "12", "bold"),
bg="white",
fg="blue",
justify='center'
)
Número_Prestação_entrada.place(relx=0.6, rely=0.4, relwidth=0.25)
# Functions
def limpar():
Número_Prestação_entrada.delete(0, END)
Prestação_entrada.delete(0, END)
resultado.set("")
def calcular_prestacao():
try:
p = Prestação.get()
n_p = Número_Prestação.get()
total = p * n_p
mensagem = f"Prestação Total: {total:.2f} €"
resultado.set(mensagem)
except ValueError:
resultado.set("Valores inválidos!")
# Buttons
but1 = Button(
text="Calcular",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=calcular_prestacao
)
but1.place(relx=0.05, 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.35, 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.65, rely=0.55, relwidth=0.25, relheight=0.1)
# Resultado
resultado = StringVar()
resultado_texto = Label(
textvariable=resultado,
font=("Arial", 12, "bold"),
bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
root.mainloop()