from tkinter import *
root = Tk()
root.geometry("450x150")
root.title("Calcular a soma 1+2+..+n")
root.configure(bg="#abcdef")
def accao():
N = entrada.get()
soma = 0
for i in range(1, N + 1):
soma = soma + i
mesagem = f"A soma é 1 + 2 + 3 + ... + " + str(N) + " = " + str(soma)
resultado.set(mesagem)
numerotexto = Label(text="Número Inteiro (N)",bg="#abcdef",fg="#ba990a",
font=("Arial","12","bold"))
numerotexto.place(relx=0.15,rely=0.25)
entrada = IntVar()
entrada_entrada= Entry(textvariable=entrada,font=("Arial","12","bold"),
bg="white",fg="#274e13",justify='center')
entrada_entrada.place(relx=0.55,rely=0.25,relwidth=0.2)
btnValidate = Button(root, text = " Validar", font=("Arial","12","bold"),
bg="#d0e0e3",fg="#0b5394", command=accao)
btnValidate.place(relx=0.4,rely=0.5)
resultado = StringVar()
resulatdoresultado =Label(textvariable=resultado,
font=("Arial",12,"bold"),bg="#f0f8ff")
resulatdoresultado.place(relx=0.1,rely=0.75,relwidth=0.8)
root.mainloop()