第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Python 后臺腳本捕獲屏幕截圖并保存到文檔

使用 Python 后臺腳本捕獲屏幕截圖并保存到文檔

撒科打諢 2023-05-09 15:15:59
我正在做一些測試活動(dòng),這需要我捕獲應(yīng)用程序/數(shù)據(jù)庫等的屏幕截圖并將其保存到文檔中。整個(gè)活動(dòng)有50多張截圖。在 Python 中有沒有一種方法可以通過它使用 Windows 快捷鍵(例如;CTRL ALT shift C)截取屏幕截圖并將圖像附加到文檔文件中。我相信 python 程序應(yīng)該像 Unix 中的 nohup 一樣在后臺運(yùn)行。
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

要使用熱鍵在 Word 中存儲(chǔ)屏幕截圖,您可以使用庫的組合。

  • 使用win32gui打開Word

  • 使用python-docx更新文檔并保存

  • 使用PyAutoGUI進(jìn)行屏幕捕獲

  • 使用鍵盤監(jiān)聽熱鍵

要使此腳本起作用,您需要在運(yùn)行腳本之前創(chuàng)建 Word 文檔。

# Need these libraries

# pip install keyboard

# pip install PyAutoGUI

# pip install python-docx

# pip install win32gui


import keyboard

import pyautogui

from docx import Document

from docx.shared import Inches

import win32gui

from PIL import ImageGrab


shotfile = "C:/tmp/shot.png"  # temporary image storage 

docxfile = "C:/tmp/shots.docx" # main document

hotkey = 'ctrl+shift+q'  # use this combination anytime while script is running


def do_cap():

    try:

        print ('Storing capture...')

        

        hwnd = win32gui.GetForegroundWindow()  # active window

        bbox = win32gui.GetWindowRect(hwnd)  # bounding rectangle


        # capture screen

        shot = pyautogui.screenshot(region=bbox) # take screenshot, active app

        # shot = pyautogui.screenshot() # take screenshot full screen

        shot.save(shotfile) # save screenshot

        

        # append to document. Doc must exist.

        doc = Document(docxfile) # open document

        doc.add_picture(shotfile, width=Inches(7))  # add image, 7 inches wide

        doc.save(docxfile)  # update document

        print ('Done capture.')

    except Exception as e:  # allow program to keep running

        print("Capture Error:", e)


keyboard.add_hotkey(hotkey, do_cap)  # set hot keys


print("Started. Waiting for", hotkey)


keyboard.wait()   # Block forever


查看完整回答
反對 回復(fù) 2023-05-09
  • 1 回答
  • 0 關(guān)注
  • 450 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號