2

I am trying to draw a screen with a filled in box in the center. I am using pygame.Surface.fill() for the box but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' objects doesn't apply to a 'tuple' object Here is my code:

my_color = (0, 0, 0)

my_rect = (100, 100, 200, 150)

box = pygame.Surface.fill(my_color, my_rect)

surf.blit(box)
Shark Coding
  • 143
  • 1
  • 10

1 Answers1

1

You just need to do it in two steps. First create the surface, then fill it. Creating a surface makes a separate image, so it takes a size not a rectangle.

my_color = (0, 0, 0)

my_rect = (100, 100, 200, 150)

my_size = ( 200, 150 )

box = pygame.Surface( my_size )
box.fill( my_colour )

surf.blit( box, my_rect )

If you just want to draw a rectangle, you can use the drawing functions, which use the base surface directly:

pygame.draw.rect( surf, my_color, my_rect )
Kingsley
  • 14,398
  • 5
  • 31
  • 53