python take screenshot of screen code example

Example 1: screenshot in python

import pyautogui


class gng() :
    myScreenshot = pyautogui.screenshot()
    myScreenshot.save('C:\File\Code\save.png')


gng()

Example 2: python take screenshot

#pip3 install PrtSc
import PrtSc.PrtSc as Screen
screenshot=PrtSc.PrtSc(True,'filename.png')

Example 3: make screen shot of specific part of screen python

import mss
import mss.tools


with mss.mss() as sct:
    # The screen part to capture
    monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
    output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)

    # Grab the data
    sct_img = sct.grab(monitor)

    # Save to the picture file
    mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
    print(output)