1

I just bought an M1 MacBook Air today for coding a pygame project, but at very beginning I had an issue with pygame video system. it won't initialize pygame window. The following code snippet works in PC, but M1 Mac just won't initialize it. the error message I got is "pygame error: video system not initialize"

I am not sure if this issue is just for M1 Mac or it is an issue for all Mac users. Does anyone know the answer and solution for this error?

Thank you very much!

    import pygame
    pygame.init() 
    screen = pygame.display.set_mode((800, 600))
    run = True
    while run:
       for event in pygame.event.get():
          if event.type == pygame.quit():
             run = False
BingZL
  • 11
  • 2
  • 2
    See if [this](https://stackoverflow.com/questions/49845387/pygame-error-video-system-not-initialized-pygame-init-already-called) solves your issue. – Christian Dean Mar 25 '21 at 04:32

1 Answers1

2

I initially thought this was an M1 mac problem, since pygame doesn't have good support for M1 mac yet.

However I see the problem:

if event.type == pygame.quit():

should be

if event.type == pygame.QUIT

Right now you're running the function pygame.quit(), which uninitializes your video system.

Starbuck5
  • 1,649
  • 2
  • 7
  • 13
  • Thank you Starbuck5. I changed the code.I ran this code in Sublime Text 3, it couldn't bring the pygame window. However, when I ran it in python IDLE it did pop up the window, but when click quit, pygame window stop respond. I think this issue is limited to M1 Mac for now. – BingZL Mar 25 '21 at 14:23
  • @BingZL that still sounds like an error in your code to me. When running a pygame program with IDLE, the window doesn't close until `pygame.quit()` is called. It sounds like your program is just ending instantly. – Starbuck5 Mar 26 '21 at 01:14
  • I added pygame.quit() to it. There is another problem. when I closed it, the window closed, but the program (python launcher still on) and I have to force quit it. Then I added quit() to it. The moment I close the window I got a pop up window saying program is still running, then I hit OK button, then program closed. It doesn't have problem when I run the same code in PC. – BingZL Mar 27 '21 at 02:14