我编写了Python代码来随机捕获屏幕快照,现在我正尝试将屏幕快照保存在列表中,以便能够将其打印出来
这是我的代码
def takeScreenshot ():
count=0
name = random.randrange(1, 1000)
full_name = str(name) + ".jpg"
myScreenshot = pyautogui.screenshot()
myScreenshot.interval = 100
# generate a random time between 120 and 300 sec
random_time = random.randrange(20, 30)
# wait between 120 and 300 seconds (or between 2 and 5 minutes)
time.sleep(random_time)
myScreenshot.save((r'C:\Users\ZainbaMuhdYunus\Desktop\shots2\shot') + full_name)
# keeps doing count
while 1:
takeScreenshot(data)
这是我已经查看过的问题的审阅代码,也许现在可以自我解释
import random
import pyautogui
import tkinter as tk
from tkinter import filedialog
root= tk.Tk()
def takeScreenshot ():
# count=0
name=random.randrange(1,1000)
full_name=str(name) + ".jpg"
myScreenshot = pyautogui.screenshot()
myScreenshot.interval = 100
# generate a random time between 120 and 300 sec
random_time = random.randrange(2,10)
# wait between 120 and 300 seconds (or between 2 and 5 minutes)
time.sleep(random_time)
myScreenshot.save((r'C:\Users\ZainbaMuhdYunus\Desktop\shots2\shot') + full_name)
# keeps doing count
counter=0
while 1:
takeScreenshot()```
答案 0 :(得分:0)
我想您所缺少的只是一个列表,其中包含所有屏幕快照并从功能中返回这些屏幕截图。像这样:
def takeScreenshot():
...
screenshot_path = r'C:\Users\ZainbaMuhdYunus\Desktop\shots2\shot' + full_name
myScreenshot.save(screenshot_path)
return screenshot_path
screenshots = []
while True:
screenshots.append(takeScreenshot())
screenshots
是一个列表,其中包含所有屏幕截图的路径