im new to python and i am having trouble with these pygame codes

  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()

and this error pop ups:
Exception has occurred: ValueError
invalid rectstyle object
File “myfolder/myfile.py”, line 9, in
screen.fill(0,0,0)
ValueError: invalid rectstyle object

i tried
screen.fill((0,0,0))
pg.draw.rect(screen, ((255,0,0)), rect)

error fixed but 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.

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

LEAVE A COMMENT