我不需要保存截图的图片,把截图放入DOCX文件中即可
时间: 2024-02-17 15:04:36 浏览: 22
好的,我修改一下之前的代码,把截图直接插入到DOCX文件中:
```python
import pyautogui
import keyboard
from docx import Document
from datetime import datetime
import tkinter as tk
from tkinter import filedialog
from threading import Thread
from PIL import ImageGrab
def record():
doc = Document()
while True:
try:
key = keyboard.read_event()
if key.event_type == "down":
now = datetime.now().strftime("%Y%m%d-%H%M%S")
screenshot = ImageGrab.grab()
screenshot_file = f"{now}.png"
screenshot.save(screenshot_file)
doc.add_paragraph(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {key.name}")
doc.add_picture(screenshot_file)
except:
pass
def start_record():
Thread(target=record).start()
def stop_record():
filename = filedialog.asksaveasfilename(defaultextension=".docx")
doc.save(filename)
def exit_program():
root.quit()
def create_gui():
root = tk.Tk()
root.title("步骤记录器")
root.geometry("300x100")
start_button = tk.Button(root, text="开始记录", command=start_record)
start_button.pack(side=tk.LEFT, padx=10)
stop_button = tk.Button(root, text="停止记录", command=stop_record)
stop_button.pack(side=tk.LEFT, padx=10)
exit_button = tk.Button(root, text="退出程序", command=exit_program)
exit_button.pack(side=tk.LEFT, padx=10)
root.mainloop()
if __name__ == "__main__":
create_gui()
```
这样,程序会在记录键鼠操作的同时,将截图直接插入到DOCX文件中。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)