pygame   documentation
||  Home  ||  Help Contents  ||
 
|| pygame || cdrom || constants || cursor || display || draw ||
|| event || font || image || joystick || key || mixer ||
|| mixer_music || mouse || movie || sndarray || surfarray || time ||
|| transform ||
 
|| CD || Channel || Clock || Font || Joystick || Movie ||
|| Overlay || Rect || Sound || Surface ||
 
|| color || cursors || sprite ||

Rect

The rectangle object is a useful object representing a rectangle area. Rectangles are created from the pygame.Rect() function. This routine is also in the locals module, so importing the locals into your namespace allows you to just use Rect().
 
Rect contains helpful methods, as well as a list of modifiable members:
  • top
  • bottom
  • left
  • right
  • topleft
  • topright
  • bottomleft
  • bottomright
  • midleft
  • midright
  • midtop
  • midbottom
  • center
  • centerx
  • centery
  • size
  • width
  • height

When changing these members, the rectangle will be moved to the given assignment. (except when changing the size, width, or height member, which will resize the rectangle from the topleft corner)
 
The rectstyle arguments used frequently with the Rect object (and elsewhere in pygame) is one of the following things.
  • an actual Rect object.
  • a sequence of [xpos, ypos, width, height].
  • a pair of sequences, representing the position and size [[xpos, ypos], [width,height]].
  • if a method takes a rectstyle argument as its only argument, you can simply pass four arguments representing xpos, ypos, width, height.
and perhaps most importantly:
  • A rectstyle argument can also be _any_ python object with an attribute named 'rect'.

clamp - move rectangle inside another
clamp_ip - moves the rectangle inside another
clip - rectangle cropped inside another
collidedict - find overlapping rectangle in a dictionary
collidedictall - find all overlapping rectangles
collidelist - find overlapping rectangle
collidelistall - find all overlapping rectangles
collidepoint - point inside rectangle
colliderect - check overlapping rectangles
contains - check if rectangle fully inside another
fit - Fill as much of the argument as possible, maintains aspect ratio
inflate - new rectangle with size changed
inflate_ip - changes the Rect size
move - new rectangle with position changed
move_ip - move the Rect by the given offset
normalize - corrects negative sizes
union - makes new rectangle covering both inputs
union_ip - rectangle covering both input
unionall - rectangle covering all inputs
unionall_ip - rectangle covering all inputs

clamp
Rect.clamp(rectstyle) -> Rect
 
clamp_ip
Rect.clamp_ip(rectstyle) -> None
 
clip
Rect.clip(rectstyle) -> Rect
 
collidedict
Rect.collidedict(dict if rectstyle keys) -> key/value pair
 
collidedictall
Rect.collidedictall(rectstyle list) -> key/val list
 
collidelist
Rect.collidelist(rectstyle list) -> int index
 
collidelistall
Rect.collidelistall(rectstyle list) -> index list
 
collidepoint
Rect.collidepoint(x, y) -> bool
 
colliderect
Rect.colliderect(rectstyle) -> bool
 
contains
Rect.contains(rectstyle) -> bool
 
fit
Rect.fit(rectstyle) -> Rect
 
inflate
Rect.inflate(x, y) -> Rect
 
inflate_ip
Rect.inflate_ip(x, y) -> None
 
move
Rect.move(x, y) -> Rect
 
move_ip
Rect.move_ip(x, y) -> None
 
normalize
Rect.normalize() -> None
 
union
Rect.union(rectstyle) -> Rect
 
union_ip
Rect.union_ip(rectstyle) -> None
 
unionall
Rect.unionall(sequence_of_rectstyles) -> Rect
 
unionall_ip
Rect.unionall_ip(sequence_of_rectstyles) -> None