from tkinter import *
root = Tk()
root.title("Validar resposta")
root.geometry("300x200")
root.resizable(0,0)
root.configure(bg="#cfe2f3")
def app ():
r = resposta.get()
if r == "2":
mensagem = "Resposta correcta"
vresultado['bg'] = 'green'
else:
mensagem = "Resposta incorrecta"
vresultado['bg'] = 'red'
resultado.set(mensagem)
def limpar():
resposta_entrada.delete(0, END)
pergunta = Label(text="Quanto é 1 + 1? ",bg="#cfe2f3",fg="black",
font=("Arial","14","bold"))
pergunta.place(relx=0.25,rely=0.1)
resposta = StringVar()
resposta_entrada= Entry(textvariable=resposta,font=("Arial","12","bold"),
bg="white",fg="red",justify='center')
resposta_entrada.place(relx=0.3,rely=0.35,relwidth=0.4)
#
but_resposta = Button( text="Validar Resposta", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=app)
but_resposta.place(relx=0.1, rely=0.55, relwidth=0.5, relheight=0.15)
but_limpar = Button( text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'), command=limpar)
but_limpar.place(relx=0.65, rely=0.55, relwidth=0.2, relheight=0.15)
resultado = StringVar()
vresultado = Label(textvariable=resultado,font=("Arial",12,"bold"),
bg="#cfe2f3",fg="white")
vresultado.place(relx=0.2,rely=0.75,relwidth=0.6)
root.mainloop()