# -*-encoding:utf-8 -*-
"""
@Time : 2024/7/17 下午3:12
@Auth : ruqing
@File :截图.py
@IDE :PyCharm
@Motto:ABC(Always Be Coding)
"""
import pyautogui
import time
import os
import pysnooper
import pygetwindow as gw



@pysnooper.snoop()
def take_screenshot(interval, save_path):
    while True:
        # 获取当前时间作为文件名
        current_time = time.strftime("%Y%m%d-%H%M%S")
        file_name = f"{current_time}.png"
        file_path = os.path.join(save_path, file_name)

        # 截取屏幕并保存为PNG文件
        screenshot = pyautogui.screenshot()
        screenshot.save(file_path)

        print(f"截图已保存到 {file_path}")

        # 等待指定的时间间隔
        time.sleep(interval)


if __name__ == "__main__":
    # 设置截图间隔(秒)和保存路径
    interval = 1200  # 每隔60秒截屏一次
    save_path = "screenshots"  # 截图保存在当前目录下的screenshots文件夹中

    # 如果保存路径不存在,则创建
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    # 开始定时截屏
    take_screenshot(interval, save_path)
截图

 

posted on 2025-06-19 14:00  Star*S  阅读(11)  评论(0)    收藏  举报