How to save pygame window as a image? (python3) (PyGame)

Viewed 428

I'm making a pixel editor / a trash version of ms paint in python with pygame, and I want to save the window (canvas?) as a png or jpg. I've seen pygame.image.save, but that only saves a certain surface as an image, I want to save the entire window.

2 Answers

Use pygame.image.save(), which requires PyGame 1.8 or later. If you give it the base-level window surface, it will indeed save the entire window content.

For example:

pygame.image.save( window, 'surface.png' )

The image type is determined by the filename suffix.

Give the following a try:

pygame.image.save(window, "screenshot.png")
Related