Skip to content

Instantly share code, notes, and snippets.

@seanmtracey
Last active July 4, 2016 08:31
Show Gist options
  • Save seanmtracey/1d81c496932710c2113d4e1c3c332ff6 to your computer and use it in GitHub Desktop.
Save seanmtracey/1d81c496932710c2113d4e1c3c332ff6 to your computer and use it in GitHub Desktop.
A snippet that enables Pygame Zero games to take screenshots during gameplay and save them to a 'screenshots' directory in the same path.
from pygame import image as PGI
import time
def take_screenshot(Surface):
outputDir = './screenshots/'
if not os.path.exists(outputDir):
os.makedirs(outputDir)
PGI.save(Surface, outputDir + str( int(time.time()) ) + '.png' )
def on_key_down(key):
if key == keys.P:
take_screenshot(screen.surface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment