6

I am learning from Al Sweigart's you tube video for automating the boring stuff. I got to the part of taking screenshots. He didn't really explain in his video so I tested things out. I found that it takes screenshots of the whole desktop but I don't know where they go. I can only find it when do a whole computer search and I don't know how to put it into a folder from there.

Basically I am asking how I can store the images and find those images taken by the pyautogui.screenshot() function. I am not planning on using this for anything at the moment I just want to know how to do it. I went to the pyautogui website and I didn't find anything on where to find and how to save the screenshots. Thank you in advance for your time!

Trevor Trinh
  • 75
  • 1
  • 1
  • 5

2 Answers2

8

Here's the link to the documentation on saving screenshots in pyautogui:

https://github.com/asweigart/pyautogui#user-content-screenshot-functions

The screenshot function returns a PIL.Image. You can save that to a file with it's save method.

import pyautogui
im1 = pyautogui.screenshot()
im1.save(r"c:\path\to\my\screenshot.png")

You can also pass the path where you'd like to save the file in the screenshot method call:

import pyautogui
pyautogui.screenshot(r"c:\path\to\my\screenshot1.png")
clockwatcher
  • 3,193
  • 13
  • 13
4

Did you follow the pyautogui doc ?

It clearly says: PyAutoGUI can take screenshots, save them to files, and locate images within the screen.

Calling screenshot() will return an Image object. It can be called in different ways :

>>> im1 = pyautogui.screenshot()  # return an image object
>>> im2 = pyautogui.screenshot('my_screenshot.png')  # image name will be as per parameter
>>> im3 = pyautogui.screenshot(region=(0,0, 300, 400)) # mention spedific region to get the screenshot 

They all return an image object which can be later used / saved as per requirement :

>>> im1.size()  # will return a dimension of image as a tuple  
>>> im2.save("<imagepath where you wish to save your image >") # save the image
>>> im.getpixel((100, 200)) # return color value of the point mentioned 
pppery
  • 3,731
  • 22
  • 33
  • 46
coder3521
  • 2,608
  • 1
  • 28
  • 50