Python 코드 20 줄 로 만 화면 녹화 기능 구현

모듈 설치
우선,우 리 는 두 개의 python 모듈,win32gui 와 PyQt 5 를 사용 해 야 합 니 다.
1.pip install win32gui
2.pip install PyQt5

1、pip install win32gui
PS C:\Users\lex\Desktop> pip install win32gui
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Requirement already satisfied: win32gui in f:\develop\python36\lib\site-packages (221.6)
Requirement already satisfied: win32core in f:\develop\python36\lib\site-packages (from win32gui) (221.36)
 
2、pip install PyQt5
PS C:\Users\lex\Desktop> pip install PyQt5
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Requirement already satisfied: PyQt5 in f:\develop\python36\lib\site-packages (5.15.4)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in f:\develop\python36\lib\site-packages (from PyQt5) (12.8.1)
Requirement already satisfied: PyQt5-Qt5>=5.15 in f:\develop\python36\lib\site-packages (from PyQt5) (5.15.2)
PS C:\Users\lex\Desktop>
2.디자인 사고
1.win32gui 모듈 을 통 해 windows 시스템 의 캡 처 기능 을 호출 하여 화면 을 녹화 합 니 다.
2.timer 타 이 머 를 통 해 2 초 간격 으로 한 번 씩 캡 처 하여 화면 사용자 의 조작 기록 을 기록한다.
3.캡 처 한 화면 을 캡 처 시간 에 따라 이름 을 짓 고 은밀 한 폴 더 경로 에 저장 합 니 다.
이렇게 하면 우 리 는 폴 더 에 있 는 사진 을 보면 알 수 없 는 로그 인 자가 컴퓨터 에서 어떤 조작 을 했 는 지 뚜렷하게 파악 할 수 있다.
3.코드 구현
간단하게 10 여 줄 의 코드 만 있 으 면 윈도 우즈 시스템 컴퓨터 화면 에 대한 녹 화 를 실현 할 수 있다.
코드 는 다음 과 같 습 니 다:

#    ,  2          
def timer(n):
    while True:  
        dt= time.strftime('%Y-%m-%d %H%M%S',time.localtime())
        screen = QApplication.primaryScreen()
        img = screen.grabWindow(record).toImage()
        img.save("D:\\images\\"+dt+".jpg")
        time.sleep(n)
if __name__ == "__main__":
    timer(2)
4.운행 방법
1.python 환경 검사
명령 행 에서 python 을 실행 하고 python 버 전 을 3.6.5 로 봅 니 다.

PS C:\Users\lex\Desktop> python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
2.프로그램 실행
명령 행 에서 python py-screen.py 를 실행 하면 됩 니 다.효 과 는 다음 그림 과 같 습 니 다.

전체 코드

from PyQt5.QtWidgets import QApplication
import win32gui
import sys
import time
record = win32gui.FindWindow(None, 'C:\Windows\system32\cmd.exe')
app = QApplication(sys.argv)
def timer(n):
    while True:  
        dt= time.strftime('%Y-%m-%d %H%M%S',time.localtime())
        screen = QApplication.primaryScreen()
        img = screen.grabWindow(record).toImage()
        img.save("D:\\images\\"+dt+".jpg")
        time.sleep(n)
if __name__ == "__main__":
    timer(2)
이야기 결말
마지막 으로 컴퓨터 캡 처 를 봤 어 요.
그냥 하 는 거 였 구나.

다행히 python 작은 오빠 는 마침내 안심 하고 잘 수 있 게 되 었 습 니 다.
파 이 썬 코드 20 줄 로 만 화면 녹화 기능 을 수행 할 수 있 는 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 파 이 썬 화면 녹화 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!

좋은 웹페이지 즐겨찾기