0

MacOSX 10.15.2, Python 3.8 and Pygame 2.0.0.

Hello! I am currently trying to make a dark purple (87,61,122) background in Pygame, but it only appears as a black background, seemingly frozen and loading forever.

Here is my code:

import pygame

bgcolor = [87,61,122]

pygame.init()
screen = pygame.display.set_mode((1600,900))
screen.fill(bgcolor)
pygame.display.flip

Is there anything wrong with the code or is Pygame just refusing to co-operate?

daysant
  • 21
  • 3

2 Answers2

1

pygame.display.flip is not a function call. You missed the parentheses.

However, you have to handle the events in the application loop. See pygame.event.get() respectively pygame.event.pump():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system. This will update the contents of the entire display.

The typical PyGame application loop has to:

import pygame

bgcolor = [87,61,122]

pygame.init()
screen = pygame.display.set_mode((1600,900))
clock = pygame.time.Clock()

run = True
while run:
    clock.tick(60)

    # handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            run = False

    # clear display
    screen.fill(bgcolor)

    # draw scene
    # [...]

    # update display
    pygame.display.flip()

pygame.quit()
exit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
0

change pygame.display.flip by pygame.display.flip() or pygame.display.update()

not that without IDLE, this script will display a window and directly destroy it. To add like loop:

import pygame

bgcolor = [87,61,122]

pygame.init()
screen = pygame.display.set_mode((1600,900))
loop = True

while loop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False #Quiting
    screen.fill(bgcolor)
    pygame.display.update()
Henry
  • 577
  • 4
  • 9