Reputation: 173
I want my python program to wait before continuing the loop. But the other functions, loops usw. should work. If I use the sleep-function the whole program would sleep. Example:
import pygame
def function():
print("You moved forward")
turtle.listen()
turtle.onkey(function, "f")
print("use f to move forward")
(Wait 5 seconds, so the player can try pressing f and sees what happens)
Thats a simple version of my original code. I want the player to try WASD cause the character is moved with WASD.
If I'd use time.sleep() it won't work if the player presses f.
Thanks for any answer :D
-> btw sry for my bad english...
Upvotes: 0
Views: 160
Reputation: 2145
If you want to wait for 5 seconds but not sleep then you can maybe try with a loop and measure the running time of the loop. Something like this maybe:
First make sure pytictoc is installed by running pip install pytictoc
Then run a loop like this maybe:
from pytictoc import TicToc
t = TicToc() #create instance of class
t.tic() #Start timer
while (t.tocvalue()<5):
pass
t.toc()
Upvotes: 1