Mundo em Python

Actualização de rendas para 2026

from tkinter import *

root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Actualização de rendas para 2026")
titulo = Label(text="Actualização de rendas para 2026",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05) texto_sub1 = Label(text="Valor actual da renda:",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.32)
valor_renda = StringVar()
valor_renda_entrada = Entry(textvariable=valor_renda,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
valor_renda_entrada.place(relx=0.45, rely=0.33, relwidth=0.4)
valor_renda_entrada.focus() # Função para limpar
def limpar():
valor_renda_entrada.delete(0, END)
resultado_texto.config(text="") # Função principal
def app():
try:
# Substitui vírgula por ponto antes de converter
valor = float(valor_renda.get().replace(",", "."))
actualizacao = 2.25 / 100
valor_renda_acrescentado = valor * actualizacao
valor_total_2026 = valor + valor_renda_acrescentado # Formata com 2 casas decimais e troca ponto por vírgula
aumento_str = f"{valor_renda_acrescentado:.2f}".replace(".", ",")
total_str = f"{valor_total_2026:.2f}".replace(".", ",") mensagem = f"Valor do aumento: {aumento_str}\n" \
f"Valor da renda para 2026: {total_str} €"

resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="⚠️ Por favor, insira um número válido.") but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.5, 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.5, 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.5, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3", anchor="center", justify="center")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
root.bind('<Return>', lambda event: app()) root.mainloop()
0