pygame window keeps not responding

spicy meatballs

After a long time trying to install pygame for 2.7 it finally installs and I now have it downloaded, but there is now the problem that it keeps not responding after a couple seconds of being open. Any answer will be appreciated, the code that I have so far is just.

import pygame

pygame.init()

pygame.display.set_mode((640,480))

so I need some help please.

Ethanol

So what you want to do, like what skrx said, is a while loop to continuously keep the code inside the while loop and the pygame window running, and as well as a for event loop, in order to be able to shut down the window. Here's how you can do it:

import pygame
pygame.init()
pygame.display.set_mode((640, 480))  # opens the display

while True:  # the while loop that will keep your display up and running!
    for event in pygame.event.get():  # the for event loop, keeping track of events,
        if event.type == pygame.QUIT:  # and in this case, it will be keeping track of pygame.QUIT, which is the X or the top right
             pygame.quit()  # stops pygame

There are other ways of stopping the while loop, and you could do this:

running = True
while running:  # the while loop that will keep your display up and running!
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
             running = False
pygame.quit()

Hope this helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related