So I'm making this subitizing trainer. It trains you to know how many of something there are without physically counting them. The program creates a window and then generates a random number of circles. Then you enter how many circles you saw, it then tells you whether you were right or wrong.
Now I want the whole program to repeat after you press a certain button on your keyboard, how would I do this?
from tkinter import *
import random
import time
def new_circle():
c1 = random.randint(1, 500)
c2 = random.randint(1, 500)
canvas.create_oval(c1, c2, c1+45, c2+45, fill='black')
def enter_text(event):
global number_of_circles
answer = int(text.get())
if answer == number_of_circles:
frame.destroy()
label = Label(window, text="That's right")
label.pack()
else:
frame.destroy()
label = Label(window, text="That's wrong")
label.pack()
window = Tk()
canvas = Canvas(window, width=1000, height=1000)
number_of_circles = random.randint(1, 2)
for i in range(number_of_circles):
new_circle()
canvas.pack()
window.after(750, canvas.destroy)
frame = Frame()
text = Entry(frame, width=50)
text.pack()
text.focus()
enter = Button(frame, command=enter_text)
enter.pack()
frame.pack()
window.bind('<Return>', enter_text)
window.mainloop()