How to copy and save an image into a new folder?
Question:
So far, I’ve only managed to prompt the user for an image:
def addImage(event=None):
fileName = filedialog.askopenfilename()
return fileName
As far as I know, this only returns the path of the image. How would I be able to let the user choose an image from their personal drive and then save it into a new folder?
Answers:
You can use the shutil
module to move or copy files to different locations
import shutil
destination = "/some/destination/path"
def addImage(event=None):
fileName = filedialog.askopenfilename()
shutil.copy(fileName, destination)
return fileName
shutil
also has functions for moving files instead of copying them, and functions for copying or moving full directories as well.
So far, I’ve only managed to prompt the user for an image:
def addImage(event=None):
fileName = filedialog.askopenfilename()
return fileName
As far as I know, this only returns the path of the image. How would I be able to let the user choose an image from their personal drive and then save it into a new folder?
You can use the shutil
module to move or copy files to different locations
import shutil
destination = "/some/destination/path"
def addImage(event=None):
fileName = filedialog.askopenfilename()
shutil.copy(fileName, destination)
return fileName
shutil
also has functions for moving files instead of copying them, and functions for copying or moving full directories as well.