This article will show you an example of how to detect the collision between rectangles and points in pygame. You can use the method pygame.Rect.collidepoint(point) to detect whether a rectangle collides a point in pygame, you can use the method pygame.Rect.colliderect(rectangle) to detect whether a rectangle object collides another rectangle object in pygame.
This article will show you examples of how to move or inflate the pygame rectangle by pressing keys, mouse, or by itself automatically.
This example will tell you how to align a rectangle in the pygame main window screen horizontally or vertically. When you press the different keyboard keys, the rectangle will be aligned to the main window screen’s left, right, top, bottom borders, center horizontally or center vertically.