I tried to draw a red rectangle in Pygame, but the screen is black

  Kiến thức lập trình
import pygame as pg

pg.init()

W, H = 500, 400
screen = pg.display.set_mode((W, H))
run = True
rect = pg.Rect(50, 50, 60, 60)
screen.fill((0, 0, 0))
pg.draw.rect(screen, (255, 0, 0), rect)

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

pg.display.flip()
pg.quit()

Why is the screen still black?

New contributor

arostybread is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT