You may experience two separated issues:
Issue 1: Pygame installation on MacOS
There are some documented problems when running PyGame with MacOS. Please check that you have correctly installed and setup pygame in your machine. This post might be useful.
Issue 2: Code incorrections
Apart from that, your code has several issues. Your running loop does not display anything since it is stuck processing events and nothing more. Therefore, you see a black screen. Notice that you are printing the screen and the circle when the execution is over.
When using pygame
I suggest to differentiate between:
- Initialisation: Setup
pygame
and screen
. Render any static content.
- Running loop: Process events and render any dynamic content.
- End: Display any end animation/object and finalise
pygame
.
I suggest the following modifications:
- Render first the screen
- In the running loop just process the events and render the circle
- I have added debug messages. You can enable and disable them by running
python mygame.py
and python -O mygame.py
. Be aware that the print
statements inside the running loop will print a lot of messages.
Here is the code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# For better print formatting
from __future__ import print_function
# Imports
import pygame
#
# MAIN FUNCTION
#
def main():
# Setup display and static content
if __debug__:
print("Initialising pygame")
pygame.init()
SCREEN_TITLE = 'Chess Game'
pygame.display.set_caption(SCREEN_TITLE)
screen = pygame.display.set_mode([500, 500])
screen.fill((255, 255, 255))
pygame.display.flip()
# Running loop
running = True
while running:
if __debug__:
print("New iteration")
# Process events
if __debug__:
print("- Processing events...")
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Display any dynamic content
if __debug__:
print("- Rendering dynamic content...")
pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
# Update display
if __debug__:
print("- Updating display...")
pygame.display.flip()
# End
if __debug__:
print("End")
pygame.quit()
#
# ENTRY POINT
#
if __name__ == "__main__":
main()
Debug output:
$ python mygame.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Initialising pygame
New iteration
- Processing events...
- Rendering dynamic content...
- Updating display...
.
.
.
New iteration
- Processing events...
- Rendering dynamic content...
- Updating display...
End
Display:
