使用 Python 在 Windows 上获取屏幕截图? [英] Get screenshot on Windows with Python?

查看:79
本文介绍了使用 Python 在 Windows 上获取屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 Beta 测试人员报告模块,以便他们可以发送对我的软件的评论,但我希望可以选择在报告中包含屏幕截图.如何在 Windows 上使用 Python 截取屏幕截图?我在 Linux 上找到了几个例子,但在 Windows 上运气不佳.

I am creating a Beta Testers reporting module so they can send in thier comments on my software, but I would like to have the option to include a screenshot with the report. How do I take a screenshot of the screen with Python on Windows? I have found several examples on Linux, but haven't had much luck on Windows.

推荐答案

另一种非常快速的方法是 MSS 模块.它与其他解决方案的不同之处在于它仅使用 ctypes 标准模块,因此不需要大的依赖项.它独立于操作系统,使用起来很容易:

Another approach that is really fast is the MSS module. It is different from other solutions in the way that it uses only the ctypes standard module, so it does not require big dependencies. It is OS independant and its use is made easy:

from mss import mss

with mss() as sct:
    sct.shot()

然后找到包含第一台显示器屏幕截图的 screenshot.png 文件.有很多可能的自定义,您可以使用 ScreenShot 对象和 OpenCV/Numpy/PIL/等.

And just find the screenshot.png file containing the screen shot of the first monitor. There are a lot of possibile customizations, you can play with ScreenShot objects and OpenCV/Numpy/PIL/etc..

这篇关于使用 Python 在 Windows 上获取屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆