0

The screen wont fill and it says there is no fill cmd for screen, what did I do wrong?

import pygame
    
pygame.init()

screen = pygame.display
set_mode((0, 0))

white = (255, 255, 255)
Square =(0, 0, 0)

loop = True
while loop:
    screen.fill(white)
    pygame.draw.rect(screen, Square, pygame)Rect(100, 100, 200, 200)
    pygame.display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

There are some syntax errors in your code:

screen = pygame.display
set_mode((0, 0))

screen = pygame.display.set_mode((0, 0))

pygame.draw.rect(screen, Square, pygame)Rect(100, 100, 200, 200)

pygame.draw.rect(screen, Square, pygame.Rect(100, 100, 200, 200))

More than that, the event loop is missing. This can cause your application to freeze. 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.

Correct program:

import pygame
    
pygame.init()
screen = pygame.display.set_mode((640, 480))

white = (255, 255, 255)
Square = (0, 0, 0)

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

    screen.fill(white)
    pygame.draw.rect(screen, Square, pygame.Rect(100, 100, 200, 200))
    pygame.display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • @ChainzGames Please follow the link: https://replit.com/@Rabbid76/It-wont-draw-my-rectangle#main.py This is the working example. Same code as in the answer. No error. – Rabbid76 Oct 11 '21 at 19:07
  • never mind it works now, thank you for the help (mainly with the indentions :) ) – Chainz Games Oct 11 '21 at 21:38