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)) 明确指定了截图区域,仅截取主显示器的内容。

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

相关推荐
冰冰菜的扣jio7 小时前
理解类加载过程
开发语言·python
qilei20107 小时前
【Python】创建日期列表
python
百***07457 小时前
GPT-5.2国内稳定接入实战指南:中转调用全链路方案(Python适配)
python·gpt·php
zyxqyy&∞8 小时前
python代码小练-4
开发语言·python
luoluoal8 小时前
基于python的反爬虫技术的研究(源码+文档)
开发语言·python·mysql
老歌老听老掉牙8 小时前
圆柱立铣刀容屑槽几何要素仿真及计算分析
python·立铣刀·容屑槽
hugh_oo8 小时前
100 天学会爬虫 · Day 11:如何合理控制爬虫请求频率?让访问行为更像真人
开发语言·爬虫·python
长安牧笛8 小时前
房贷提前还款测算程序,输入贷款总额,利率,还款年限,计算提前还款后的利息节省金额和月供变化。
python
嘻哈baby8 小时前
Python开发Telegram Bot实现服务器监控告警
python
UtopianCoding8 小时前
什么是NoteDiscovery?Obsidian 的开源平替?
python·docker·开源