Teach Yourself Python: Take Screenshots

There is a screen capture function in the pyautogui module, and the captured image will generate a Pillow Image object. Next, use the screenshot() method in the pyautogui module to execute the screenshot and save it.

Enter the following code:

import pyautogui as p

tp=p.screenshot('11.jpg')#You can use this method to save as 11.jpg

tp.save('12.jpg')# can also be saved as 12.jpg using this method, the image content is the same

You can also use the pillow module Image.crop() function to cut the image method. The specific operations are as follows:

import pyautogui as p

tp=p.screenshot()

jt=tp.crop((50,20,800,400))#The distance between the parameters and the upper left and lower right

jt.save(‘12.jpg’)

After execution, you can see a cropped image.

————————————————

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326945537&siteId=291194637