Thalis
Thalis

Reputation: 176

Is there a problem with PyCharm or my computer?(Mac) that doesn't let me open the simplest window?

When I run the following program nothing appears on my screen as you can see. The only thing I can see is the pygame icon going up and down

This is the code:

import pygame

pygame.init()

window=(800,600)
screen=pygame.display.set_mode(window)

background = pygame.Surface(window)
background.fill((255,0,0))

loop=True
while loop:
    screen.fill((0,0,0))
    screen.blit(background, (0,0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False
            pygame.quit()


pygame.display.update()

The program does nothing. I only see the python launcher icon going up and down. Maybe it is a problem with my editor? (PyCharm) or my computer(Mac)? I'm a beginner and I haven't ever run into this kind of problem.

Upvotes: 2

Views: 94

Answers (2)

Thalis
Thalis

Reputation: 176

Finally it worked for me. I uninstalled and reinstalled pygame and now it works.

Upvotes: 1

Qiu YU
Qiu YU

Reputation: 519

Try this code:

import pygame, sys
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((800,800))

while 1:
    screen.fill((255,0,0))
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
            
    pygame.display.update()

This code works on my computer. I'm using PyCharm on a mac.

Upvotes: 2

Related Questions