How to capture pygame screen?

lalli picture lalli · May 22, 2011 · Viewed 16.6k times · Source

How can I capture and save a sequence of images or a video of a pygame screen?
Basically I want to share my game video on youtube. Also, want to make a tutorial.

The game is rendered mainly in a loop:

def main():
    while True:
        GetInput()
        Move()
        Shift()
        Draw()

With the Draw() function doing all the blit() and stuff before doing the pygame.display.flip()

Answer

sam hocevar picture sam hocevar · May 22, 2011

Use pygame.image.save on your screen surface:

window = pygame.display.set_mode(...)

...

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

Note that this will slow down your program tremendously. If it is time-based, you may wish to fake the framerate when doing a capture.