我在 Catalina 之前使用过库 pyscreenshot在 Python 中以编程方式制作屏幕截图。
我不知道操作系统更新是否破坏了某些内容,但因为当我从代码中截取屏幕截图时,
例如
# bbox declared in context
import pyscreenshot as ImageGrab
if os.name == 'nt':
# Windows
im = ImageGrab.grab(bbox=bbox)
else:
# macOS (I don't worry about Linux)
im = ImageGrab.grab(bbox=bbox, backend='mac_quartz', childprocess=False)
# ...
im.save(filename)
我得到的是干净桌面的屏幕截图,而不是屏幕上显示的应用程序。
我也尝试过(虽然丑陋但比什么都没有有效的东西更好)
os.system("screencapture %s" % filename)
但是同样的事情发生了。
有办法解决这种情况吗?
最佳答案
您需要进入系统偏好设置>安全和隐私
并允许您的终端处于屏幕录制选项下,然后它应该允许您截取屏幕截图。
关于python - 自 Catalina 以来,在 macOS 上不再使用 Python 截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59732947/