0

Here is my code:

import pygame
pygame.init()
screen = pygame.display.set_mode((200,200))
clock = pygame.time.Clock()
while True:
    color = (100,100,200)
    screen.fill(color)
    pygame.display.flip()
    clock.tick(60)

I think this should create a 200x200 window and fill it with the RGB color (100,100,200). Instead of this, it creates a blank 200x200 window. When I control-c to quit, the window flashes the correct color for one or two frames then closes. Why is this?

  • 1
    Possible duplicate of [Pygame window not responding after a few seconds](https://stackoverflow.com/questions/20165492/pygame-window-not-responding-after-a-few-seconds) – skrx Sep 04 '18 at 08:50
  • @skrx It is the same issue, but I would suggest you keep this question up as the symptoms of the mistake can be different. – Riley Madison Sep 05 '18 at 21:35

1 Answers1

1

Thanks to siliconwolf on the PyGame Discord server, here is the answer:

If you don't process PyGame events with pygame.event.get(), then you must use pygame.event.pump() at the beginning of the loop or the window will freeze. However, pygame.event.get() is strongly preferred because you may have issues closing the window otherwise.