I want to draw a rectangle filled with one color and border with another color. Something like this:
And I can draw two rectangles, one is filled with some color and the other one has just borders:
pygame.draw.rect(screen, "red", (100, 100, 100, 100))
pygame.draw.rect(screen, "green", (100, 100, 100, 100), 5)
But, is there any better way?
Technically there is no better way. You have to draw 2 rectangles. A rectangle can only have one uniform color. There is no separate argument for the color of the border. See pygame.draw.rect()
. You can write it with one line of code (list comprehensions), but you still have to draw 2 rectangles:
[pygame.draw.rect(screen, c, (100, 100, 100, 100), w) for c, w in [("red", 0), ("green", 5)]]