我编写了一个 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()```
最佳答案
我认为您缺少的只是一个包含所有屏幕截图并从函数返回这些屏幕截图的列表。像这样的东西:
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
是包含所有屏幕截图路径的列表
关于python - 有没有办法可以用 python 将屏幕截图的输出保存在列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60190690/