I want the user to be able to save their work as an image in a Paint app I'm making with Pygame. Just wanted to know if there's a way to have a file browser pop up so the user could choose the save location manually each time?
I am currently using an absolute path to have the images saved on my desktop:
def generate_file_name(num):
"""
Recursively looks for a file name that doesn't exist in folder for saving a screenshot
:param num: Suffix for the file name
:return: Valid file name
"""
file_name = 'C:/Users/yargr/Desktop/screenshot'
if num == 0: # First call
file_name += '.jpg'
else:
file_name += str(num) + '.jpg'
try: # Look for a file by that name
pygame.image.load(file_name)
except: # File doesn't exist - name is valid
return file_name
else: # Name exists - try again with new suffix
file_name = generate_file_name(num + 1)
return file_name
[...]
def main():
[...]
screenshot = screen.subsurface(canvas)
file_name = generate_file_name(0)
pygame.image.save(screenshot, file_name)
Any suggestions? Thanks!