我用PIL imagegrab保存的每个屏幕截图的单独名称

2024-09-28 05:28:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用PIL创建一个python脚本,在使用时保存一个屏幕截图,但我希望它在使用时保存带有单个名称的屏幕截图。例如:截图1、截图2等

我已经有代码,保存一个sceenshot,但在第二次使用它覆盖了最后一个屏幕截图

from PIL import ImageGrab
from PIL import Image
import time


time.sleep(1)
img = ImageGrab.grab()
img.save ('screenshot.jpg', 'JPEG')

Tags: 代码fromimageimport脚本名称imgpil
1条回答
网友
1楼 · 发布于 2024-09-28 05:28:22
 import datetime
 count=0
 while(True):
     count+=1
     str_time=datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
     img.save("screenshot_"+str_time+".jpg",'JPEG')
     time.sleep(1)

使用上述代码递增计数器并保存图像

相关问题 更多 >

    热门问题