Apoio aos jovens de habitação

from tkinter import *
from datetime import datetime

root = Tk()
root.geometry("400x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Apoio aos jovens de habitação")

titulo = Label(text="Apoio aos jovens de habitação",
font=("Arial", 19, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)

# Birthdate Label and Entry
texto_sub1 = Label(text="Data de Nascimento:",
font=("Arial", 15, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.1, rely=0.2)
Data_Nascimento = StringVar()
Data_Nascimento_entrada = Entry(textvariable=Data_Nascimento,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Data_Nascimento_entrada.place(relx=0.62, rely=0.21, relwidth=0.33)
Data_Nascimento_entrada.focus()

texto_sub2 = Label(text="Valor do Imóvel:",
font=("Arial", 15, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.2, rely=0.35)
Valor_Imóvel = StringVar()
Valor_Imóvel_entrada = Entry(textvariable=Valor_Imóvel,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Valor_Imóvel_entrada.place(relx=0.62, rely=0.36, relwidth=0.33)

texto_sub3 = Label(text="Valor do Ordenado:",
font=("Arial", 15, "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.1, rely=0.5)
Valor_ordenado = StringVar()
Valor_ordenado_entrada = Entry(textvariable=Valor_ordenado,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
Valor_ordenado_entrada.place(relx=0.62, rely=0.5, relwidth=0.33)

def limpar():
Valor_ordenado_entrada.delete(0, END)
Valor_Imóvel_entrada.delete(0, END)
Data_Nascimento_entrada.delete(0, END)
resultado_texto.config(text="")

def app():
try:
ordenado = float(Valor_ordenado.get())
imovel = float(Valor_Imóvel.get())
data = Data_Nascimento.get()
birthdate = datetime.strptime(data, '%d/%m/%Y')
today = datetime.today()
idade = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))

if idade < 18:
resultado_texto.config(text="Deve ter pelo menos 18 anos para ser elegível.")
elif idade > 35:
resultado_texto.config(text="Deve ter até 35 anos para ser elegível.")
elif imovel > 450000:
resultado_texto.config(text="O valor do imóvel não pode exceder 450.000.")
elif ordenado > 5800:
resultado_texto.config(text="O ordenado deve ser até 5800.")
else:
garantia = min(0.15 * imovel, 675000)
resultado_texto.config(text=f"Você é elegível para apoio. Garantia do Estado: {garantia:.2f} euros.")
except ValueError:
resultado_texto.config(text="Erro de Digitação")

but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.6, 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.6, 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.6, relwidth=0.25, relheight=0.1)

resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.75, relwidth=0.9, relheight=0.2)

root.mainloop()

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação