How to pause a while loop in python

Started by
1 comment, last by markr 11 years, 6 months ago
I would like to know how to pause a while loop in python. Right now i am using :
[source lang="python"]raw_input("-->")[/source]
This method works, but this requires them to hit enter in the command prompt window that is open with the program. I was wanting them to just be able to hit enter and cycle through the loop with the game window selected. After several searches on google i came here because the only help with this issue was using the raw_input() functions.

Heres my while loop currently:
[source lang="python"]#Game loop

while game:
x = random.randint(1, 10)

DISPLAY.blit(gbg, (0, 0))

#the pplrty determiner
if x == 1:
p += 2
if x == 2:
p -= 2
if x == 3:
p += 3
if x == 4:
p -= 3
if x == 5:
p += 5
if x == 6:
p -= 5
if x == 7:
p += 3
if x == 8:
p -= 5
if x == 9:
p += 0
if x == 10:
p += 0

if p >= 50 and p < 60:
DISPLAY.blit(pplrty_decent, (225, 400))

elif p >= 60 and p < 85:
DISPLAY.blit(pplrty_good, (255, 400))
elif p >= 85 and p < 100:
DISPLAY.blit(pplrty_great, (255, 400))
elif p >= 25 and p < 50:
DISPLAY.blit(pplrty_bad, (225, 400))
elif p < 25:
DISPLAY.blit(pplrty_awful, (225, 400))


for event in pygame.event.get():

if event.type == QUIT:
pygame.quit()
sys.exit()
raw_input('-->')
pygame.display.update()

[/source]
Advertisement
You'll need to use the pygame keyboard functions to wait for a keypress instead of using raw_input. raw_input is only for the terminal, which you may not have, or may not use, when you have a Pygame window open.

Alternatively, you can keep your game loop spinning and just not update any objects. You might want to consider writing some functions.
You'll need to use the pygame keyboard functions to wait for a keypress instead of using raw_input. raw_input is only for the terminal, which you may not have, or may not use, when you have a Pygame window open.

Alternatively, you can keep your game loop spinning and just not update any objects. You might want to consider writing some functions.

This topic is closed to new replies.

Advertisement