import pyautogui
trial = "hello"
save_path = r"C:\Users\Dell\Desktop\hello.png"
sc1 = pyautogui.screenshot()
sc1.save(save_path)我正在尝试拍摄截图,并将它们放在我的桌面上。是否有方法通过编辑试用变量中的名称来保存具有不同名称的图片?例如,如果我在trail变量中键入了嘿嘿,则应该将图片保存为桌面中的嘿嘿。我试图修改路径,但它没有工作,因为,我认为我不能修改路径。
发布于 2020-09-20 17:32:44
使用f-string,这样:
import pyautogui
trial = "hey"
save_path = f"C:\\Users\\Dell\\Desktop\\{trial}.png"
sc1 = pyautogui.screenshot()
sc1.save(save_path)发布于 2020-09-20 17:37:43
这应该会有帮助:
import pyautogui
trial = "hello"
save_path = r"C:\Users\Dell\Desktop\{}.png".format(trial)
sc1 = pyautogui.screenshot()
sc1.save(save_path)https://stackoverflow.com/questions/63981793
复制相似问题