Skip to content
Advertisement

Prompt user to choose the name and location when saving a pdf (python)

How can I change my code so I can save my final pdf (MergedFiles.pdf) with a name chosen by the user and in a location chosen by them. I would like to have a popup(maybe tkinter?) that will give the user the option of choosing the name and location to save the pdf file.

JavaScript

Advertisement

Answer

You can do this with a tkinter filedialog.

JavaScript

Firstly, it creates and hides a tkinter window. If you didn’t do this an empty window would come up when you launched the file dialog. Then it uses filedialog.asksaveasfilename to launch the native OS file dialog. I’ve specified that it should ask for PDF files only. Then the if statement checks if a path has been returned, if it has it follows the same process as before.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement