[PyGame] Why did they put a while loop here? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: [PyGame] Why did they put a while loop here? (/thread-34091.html) |
Why did they put a while loop here? - Pedroski55 - Jun-25-2021 I know nothing about pygame, just started learning about it. I got the code below from here. I just put it in a function for trying it out in the Idle shell. This draws a rectangle OK, but isn't the while loop always working?? Wouldn't it be enough to just draw the rectangle? def rect(): import pygame pygame.init() scr = pygame.display.set_mode((500,500)) color = (0,0,255) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.draw.rect(scr, color, pygame.Rect(60, 60, 100, 100)) pygame.display.flip() pygame.quit() RE: Why did they put a while loop here? - Yoriz - Jun-25-2021 The loop is needed to get user input and to update the display. The loop will exit if the following statement is true if event.type == pygame.QUIT: running = False https://pygame.readthedocs.io/en/latest/1_intro/intro.html#show-the-event-loop Wrote:Show the event loop https://pygame.readthedocs.io/en/latest/1_intro/intro.html#quit-the-event-loop-properly Wrote:Quit the event loop properly RE: Why did they put a while loop here? - Pedroski55 - Jun-25-2021 Thanks, I have bookmarked the pygame docs page. Now I know where to look! |