Pygame failing to draw on Mac

Viewed 2832

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

7 Answers

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

Pygame still not working on Python 3.7.3, pygame 1.9.5, on OS X Mojave 10.14.3

So pygame 1.9.5 does not fix the issue.

In a simple test program (see below) window opens, window caption works, but nothing is drawn.

import pygame
import sys
pygame.init()

screen = pygame.display.set_mode((612,792))
pygame.display.set_caption("This works!")

red = (255,0,0)
screen.fill(red)

# point (0,0) is at upper left                                                             
pygame.draw.lines(screen,black,False,[(100,100),(150,200),(200,100)], 1)

pygame.display.update() #nothing is drawn

while (True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit(); sys.exit();

Using python 3.8 and couldn't load images. Working as expected after pip3 install pygame==2.0.0.dev10

For me I had to install Python version 3.6.0 of the Python page after using pip3 install pygame version 1.9.6

that works for me

For me i had to install

python 3.6 and pygame 1.9.6

on macOS Mojave 10.14.6 plus I had to add pygame.display.update()

I think you forgot pygame.display.update() to update the screen. Also, for pygame.draw.rect(win, (255,0,0), (50,50,50,50)), that means that you draw a rectangle with the top-left corner at (50,50) (first two parts) with a width and length of 50 pixels each. (last two parts).

Related