Screen Capture by PIL

Reference

https://stackoverflow.com/questions/24370228/python-imaging-library-fails-to-grab-whole-screen

Envirionment

macOS BigSur

Visual Studio Code

Python 3.8.5 64bit

Prerequisites

$ pip install pillow

Add permission to the application which run this code. In this case, the code is running under the Code (Visual Studio code), and the Code has to be checked for capturing screens as follows.

Code

from PIL import ImageGrab
import os
import time


def screenGrab():
    box = (0, 0, 1920, 1080)
    im = ImageGrab.grab(box)
    im.save(os.getcwd() + '\\screenshot_' + str(int(time.time())) + '.png', 'PNG')


def main():
    screenGrab()

if __name__ == '__main__':
    main()

投稿者: admin

Free Software Engineer

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です