Mundo em Python

Mostrar se ultrapassou o orçamento

from tkinter import *
from tkinter import messagebox
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#405fa8")
root.title("Mostrar se ultrapassou o orçamento") titulo = Label(text="Mostrar se ultrapassou o Orçamento",
font=("Arial", "15", "bold"),bg="#405fa8",fg="#f0f4ff")
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(text="Gastos Efectuados:",
font=("Arial", "15", "bold"),bg="#405fa8",fg="#f0f4ff")
texto_sub1.place(relx=0.05, rely=0.3) gasto = DoubleVar()
gasto_entrada = Entry(textvariable=gasto,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
gasto_entrada.place(relx=0.55, rely=0.3, relwidth=0.4)
def limpar():
gasto_entrada.delete(0, END)
resultado.set("")
soma = 0
def app():
global soma
orcamento = 500
gasto_atual = gasto.get()
soma = gasto_atual + soma
somaanterior = soma -gasto_atual
if soma > orcamento:
resultado.set("AVISO: O orçamento foi ultrapassado!")
messagebox.showerror("Atenção", f"O orçamento foi ultrapassado!\n Soma Anterior: {somaanterior}")
else:
resultado.set("O orçamento está dentro do limite.") but1 = Button(text="Verificar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, 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.35, 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.65, rely=0.5, relwidth=0.25, relheight=0.1)
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()
0