Python截屏程序

说明:必须安装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()

你可能感兴趣的:(C++,c,python,OS,C#)