do a while loop or restart the program on Tkinter with new question

Asked

Viewed 64 times

1

I would like to know how to do when click the reply button, restart the program with a new account and optimizing 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()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.