使用 Python 模块 pyautogui,截取屏幕截图并按日期和时间自动命名 .png 文件

Using Python module pyautogui, to take a screenshot and auto name the .png file by date&time

我正在创建一个最终会通过截图读取屏幕的程序,我需要它来保存带有日期和时间戳的文件名,该程序运行良好但没有正确创建文件名,因此正在替换现有的截屏。如何将其更改为文件名成为以下代码中定义的日期和时间的位置?

def getTime():



    #GET THE CURRENT DATE AND TIME
    now = datetime.datetime.now()
    now_str = now.strftime("%Y-%m-%d-%H-%M-%S")
    outFile = pyautogui.screenshot('ImageFile.PNG'.format(now_str))

您缺少括号。 https://docs.python.org/2/library/string.html#format-examples

outFile = pyautogui.screenshot('ImageFile{}.PNG'.format(now_str))