4

I am new to Python and Pygame, and right now I'm trying to open a test window with some simple code :

import pygame, sys

from pygame.locals import *
pygame.init()

DISPLAYSURF = pygame.display.set_mode((400, 300))

pygame.display.set_caption('Hello World!')

while True: # main game loop

    for event in pygame.event.get():

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

            sys.exit()
    pygame.display.update()

When I try to run it, I get the welcome message in terminal ("pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html"), and the python launcher starts, but it never opens. The icon simply bounces in the dock for a while, and then says Application Not Responding.

Python Launcher initialized normally with other code that doesn't use pygame, and python, pip and pygame are all up to date. I have also tried to run other pieces of code from tutorials, but everything gets the same result. I installed the new macOS Catalina today, if that makes a difference.

Thanks for your help!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • There is not any obvious issue in this code. – Rabbid76 Nov 09 '19 at 22:31
  • I am unable to reproduce the error. – Kenivia Nov 09 '19 at 22:34
  • 2
    Could you add a few print statements through the code to see where the code gets to? (e.g after `set_caption`, inside the for loop, before and after `update`) Also interesting information would be platform + python version) – MegaIng Nov 10 '19 at 10:21

2 Answers2

6

I had the exact same problem with essentially the same code above, and upgrading the pygame library solved the issue, as answered by Tom-cz in a similar issue https://stackoverflow.com/a/60496097/13407487.

If you run the above code in IDLE or python console, you'll see it cause the Python Launcher to hang (and bounce in the dock) with no window appearing:

DISPLAYSURF = pygame.display.set_mode((400, 300))

The solution was to upgrade pygame:

python3 -m pip install pygame==2.0.0.dev6

My setup: MacOS Catalina 10.15.4 Python 3.8.1 pygame 1.9.6 -> which I upgraded to 2.0.0.dev6

scottmac991
  • 61
  • 1
  • 2
0

You could install the specific version of pygame.Do this in prompt:

pip3 install pygame==2.0.0.dev6
jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49