FluffyFlounder
FluffyFlounder

Reputation: 138

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

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.

Upvotes: 3

Views: 1689

Answers (2)

jay4399
jay4399

Reputation: 43

Give the following a try:

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

Upvotes: 4

Kingsley
Kingsley

Reputation: 14906

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.

Upvotes: 3

Related Questions