1

I am creating a pygame window using the python 2.7.16 interpreter on macOS Mojave. It loads with the appropriate window size and location, but it does not add a background color, and I am not able to draw shapes on this background.The pygame window remains a blank white surface without any change in color no matter what is drawn to the draw surface and the background.

The screen should be red, but no matter what values I pass to the self.screen.fill((int, int, int)) method, it does not change color.

constants.py

pygameWindowWidth = 1500
pygameWindowDepth = 1500

realTimeDraw.py

from pygameWindow import PYGAME_WINDOW

pygameWindow = PYGAME_WINDOW()

print(pygameWindow)

while True:
    pygameWindow.Prepare()
    pygameWindow.Draw_Black_Circle(100,100)
    pygameWindow.Reveal()

pygameWindow.py file

import pygame
from constants import *

class PYGAME_WINDOW:
    def __init__(self):
        pygame.init()
        self.width = pygameWindowWidth
        self.depth = pygameWindowDepth
        self.screen = pygame.display.set_mode((pygameWindowWidth, pygameWindowDepth))

    def Prepare(self):
        self.screen.fill((255, 0, 0))

    def Reveal(self):
        pygame.display.update()

    def Draw_Black_Circle(self, x, y):
        pygame.draw.circle(self.screen, (255, 0, 0), (x, y), 45, 0)
        pygame.display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
hengjun
  • 25
  • 3

1 Answers1

1

To make the program work, you've to handle the events which are pending in the event queue, by either pygame.event.pump() or pygame.event.get(). e.g.:

pygameWindow = PYGAME_WINDOW()

run = True
while run:

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

    pygameWindow.Prepare()
    pygameWindow.Draw_Black_Circle(100,100)
    pygameWindow.Reveal()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174