The pi3d library includes a useful screenshot function to capture the screen in a .jpg or .png file. We can add a new key event to trigger it and call pi3d.screenshot("filename.jpg") to save an image (or use a counter to take multiple screenshots), as shown in the following code:
shotnum = 0 #Set counter to 0 while DISPLAY.loop_running() ... if inputs.key_state("KEY_P"): while inputs.key_state("KEY_P"): inputs.do_input_events() # wait for key to go up pi3d.screenshot("screenshot%04d.jpg"%( shotnum)) shotnum += 1 ...