Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame failing to draw on Mac

First of all, I'm on macOS Mojave 10.14.1 with pygame 1.9.4.

Also, I am using the PyCharm IDE and am using python 3.7.1.

I decided that it would be interesting to try out pygame, but drawing even a simple rectangle or image does not work.

Here is the code I have tried using to draw a rectangle, draw an image that is in the same directory as the file, and fill the window with white. None of which work.

import pygame

pygame.init()

win = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Snake")
image = pygame.image.load("java_logo.png")

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        win.fill((0, 255, 0))
        pygame.draw.rect(win, (255, 0, 0), (50, 50, 50, 50))
        win.blit(image, (200, 200))
        pygame.display.flip()

pygame.quit()

Edit:

Here was the image used: https://i.imgur.com/OoSHkXX.png

like image 970
Gigi Bayte 2 Avatar asked Nov 16 '18 19:11

Gigi Bayte 2


2 Answers

This is known-issue Pygame not compatible with MacOS Mojave #555

According to issue's comments it has been fixed in pygame 1.9.5 only

UPD: It should work for python 3.6.5

like image 197
jctim Avatar answered Oct 18 '22 21:10

jctim


I've got the same problem than you last night. None window is loading when executing a very simple pygame code, a ball bouncing in a window. The solution as related by other members is to install a newer version of pygame, in my case install the latest beta version of v2.0 of pygame lib.

Here shell code to install in OS X Mojave with python3 installed.

pip3 install pygame=2.0.0.dev6
like image 6
Jorge Vega Sánchez Avatar answered Oct 18 '22 22:10

Jorge Vega Sánchez