Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 797
FluffyFlounder Avatar asked Oct 27 '25 16:10

FluffyFlounder


2 Answers

Give the following a try:

pygame.image.save(window, "screenshot.png")
like image 186
jay4399 Avatar answered Oct 29 '25 06:10

jay4399


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.

like image 37
Kingsley Avatar answered Oct 29 '25 06:10

Kingsley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!