I'm using Tkinter to make a pi-memorization game. (Python 2.7) My main loop has to both update the Tkinter window, and display new digits of pi for you to copy. My first code for the loop was
wait = 5
for digit in pilist:
if wait > 1:
wait -= 1
display.delete("all")
display.create_text((50, 50), text=digit)
tk.update()
time.sleep(wait)
This worked fine, the speed increased, and the numbers advanced. But typing into the entry widget appeared sluggish, because it would only update every loop, and the loop was slowed down. Then I tried this:
wait = 5
initialtime = time.time()
for digit in pilist:
if wait > 1:
wait -= 1
newtime = time.time()
if newtime - initialtime >= wait:
initialtime = time.time()
display.delete("all")
display.create_text((50, 50), text=digit)
tk.update()
The list would update fine, but my list (with 333 elements in it,) would skip elements, because the list would advance, even though the only numbers being displayed were the ones that happened to fall every wait seconds when the if statement became true. So, how do I advance the list every wait seconds, but still update faster? I hope my question is clear.