pyautogui库的screenshot()函数

python 复制代码
# 方法一
screenshot = pyautogui.screenshot()
screenshot.save("screenshot.png")

# 方法二
# 获取屏幕分辨率
screen_width, screen_height = pyautogui.size()

# 截取桌面屏幕
screenshot = pyautogui.screenshot(region=(0, 0, screen_width, screen_height))
screenshot.save("screenshot.png")

截图范围:

pyautogui.screenshot() 默认会截取整个屏幕的内容,包括所有显示器。

如果系统是多显示器环境,这段代码会截取所有显示器的屏幕内容。

截图范围:

pyautogui.size() 获取的是主显示器的分辨率(screen_width 和 screen_height)。

pyautogui.screenshot(region=(0, 0, screen_width, screen_height)) 明确指定了截图区域,仅截取主显示器的内容。

如果系统是多显示器环境,这段代码只会截取主显示器的内容,而不会包括其他显示器。

相关推荐
小小代码狗11 分钟前
SQLi-Labs 基础注入实战教程(Less-1 ~ Less-5and Less-9)
服务器·python·php
nanawinona1 小时前
2026年下半年量化学习,不同基础要查不同缺口
人工智能·python
CTA量化套保1 小时前
最新量化表达入门,从概念规则到简单实现
人工智能·python
吃饱了得干活2 小时前
别再手动解析 LLM 输出了!LangChain 四种结构化输出方案对比
后端·python·langchain
ikun_文2 小时前
Python进阶—函数编程
python·pycharm
MC皮蛋侠客2 小时前
uv 系列(三):依赖、锁文件与环境同步——可重复构建的核心
python·uv
量化吞吐机2 小时前
2026年交易想法转Python,中间先补规则转译
人工智能·python
用户298698530142 小时前
Python 实现 Excel 与 Markdown 互转的实用指南
后端·python·excel
决战灬2 小时前
langgraph之interrupt(事例篇)
人工智能·python·agent
IPdodo_2 小时前
Codex 总是 Reconnecting?从 401 到响应流中断的排查方法
python·requests