pygame.draw.rect() too many parameters

Viewed 414

I'm trying to draw a hollow rectangle with rounded edges in pygame this is my code:

pygame.draw.rect(screen,(0,0,0),(350,400,200,100),5,5)

And it says "TypeError function takes at most 4 arguments (5 given)". I wonder if it has anything to do with the version of pygame I'm using, I have pygame 1.9.6. I have looked at the pygame documentation and it says that I shoud be able to use up to 9 parameters.

2 Answers

The border_radius parameters were only added to PyGame version 2.0.0.dev8.

If you are using an older version of PyGame, this operation can be performed by drawing circles at the corners:

def drawRoundedRect( screen, rect, colour=(128,128,128), radius=7 ):
    x, y   = rect.topleft
    width  = rect.width
    height = rect.height
    pygame.draw.circle( screen, colour, ( x+radius, y+radius ), radius )                  # TL corner
    pygame.draw.circle( screen, colour, ( x+width-radius-1, y+radius ), radius )          # TR corner
    pygame.draw.circle( screen, colour, ( x+radius, y+height-radius-1 ), radius )         # BL corner
    pygame.draw.circle( screen, colour, ( x+width-radius-1, y+height-radius-1 ), radius ) # BR corner
    # In-fill
    pygame.draw.rect( screen, colour, ( x+radius, y, width-(2*radius), height ) )
    pygame.draw.rect( screen, colour, ( x, y+radius, width, height-(2*radius) ) )

This was actually already answered in this post essentially the border_radius is something added in a later version then you are using.

Related