Images widget allows for displaying unclickable images on the screen, with support for special effects like rotation animations.
Constructor
Parameters
The pygame surface to which the image will draw itself
Path to the image file to load
The position of the image on the surface
The type of image. Use
"Spinner" for rotating animationImage Types
Static Images
Regular images that display without animation.game.py
Spinner Images
Images that rotate continuously, making a full rotation every second (at 30 FPS).game.py
Properties
rect
The pygame.Rect representing the image’s bounding box.count
Frame counter used for spinner animation timing.imgwidth, imgheight
Dimensions of the loaded image.Methods
draw()
Renders the image to the surface. For spinners, handles rotation logic.Spinner Animation
Spinners rotate in 90-degree increments at specific frame counts, making a full rotation every 30 frames (1 second at 30 FPS):widgets.py
The rotation implementation adjusts the rect position to compensate for how Pygame handles rotated images. The source code notes that “rotations didn’t work well on diagonals” and this is mainly for testing purposes.
Usage in Game Loop
Add images to your world list to have them drawn automatically:game.py
Implementation Details
Images are loaded with alpha channel support for transparency:widgets.py
widgets.py
Related Widgets
- Button - For clickable images with interaction
- Moving Objects - For animated moving images with collision detection