The official pygame documentation states that there are several virtual attributes which can be used to move and align a pygame.Rect
instance:
Until now I used myRect.w
respectively myRect.h
to determine the width or height of an pygame.Rect
object. But to complete this graphic I came across the .width
and .height
attributes.
The interesting thing is that both attributes seem to provide us the same date, as you can see in following code listing:
>>> myRect = pygame.Rect((10, 20), (200,100)) #create a new Rect instance
>>> myRect.w
200
>>> myRect.width
200
>>> myRect.size
(200, 100)
What´s now the difference between these two attribute pairs?
There's no difference. You can take a look at the source of the
Rect
class:You can see e.g. that both
w
andwidth
callrect_getwidth
:I would still recommend using
width
/height
instead ofw
/h
for readability.