说明:必须安装PIL库
# -*- coding:UTF-8 -*-
'''
Created on 2010-5-6
@author: shiyong
'''
import os
from PIL import ImageGrab
import time
class Capturer(object):
'''截屏程序'''
def capture(self,path='C:\\images'):
'''
截屏并保存图片至path目录下
'''
if not os.path.isdir(path) or not os.path.exists(path):
os.makedirs(path)
cutime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
filename = path+'\\'+cutime+'.gif'
im = ImageGrab.grab()
im.save(filename)
if __name__ == '__main__':
cer = Capturer()
while True:
time.sleep(2)
cer.capture()
本文介绍了一个使用Python和PIL库实现的简单截图程序。该程序能够定时自动捕获屏幕,并将截图保存到指定路径。文件中包含完整的源代码,演示了如何使用PIL中的ImageGrab模块进行屏幕抓取。
2万+

被折叠的 条评论
为什么被折叠?



