make a while loop or restart the program in tkinter with a new question

1

I would like to know how to do when I click the answer button, restart the program with a new account and optimize the code?

from tkinter import*
from random import randrange

janela=Tk()
janela.geometry('100x80')
janela.resizable(0,0)

a=(randrange(0,9))
b=(randrange(0,9))

def solucao():
    if float(campoResposta.get()) == a+b:        
        #print('Correto!')
        rotuloSolucao['text'] = 'Correto!'
    else:        
        #print('Errado')
        rotuloSolucao['text'] = 'Errado!'

    limpar()   

def limpar():
    campoResposta.delete(first=0,last=10)

rotuloQuestao = Label(janela, text='Quanto é {} + {}: '.format(a,b),bg='green')
rotuloQuestao.pack(fill=X)

campoResposta = Entry()
campoResposta.pack()

botaoResponder= Button(janela,text='Responder', command=solucao)
botaoResponder.pack()

rotuloSolucao = Label(bg='yellow')
rotuloSolucao.pack(fill=X)

janela.mainloop()
    
asked by anonymous 09.06.2018 / 00:25

0 answers