Here is a "one-line" solution like you are seeking....
It allows you to select multiple files from a dialog box and will print the list of files as a list. To be safe you should check to make sure the OK button was clicked by looking at the value of event
import PySimpleGUI as sg
event, values = sg.Window('Window Title').Layout([[sg.Input(key='_FILES_'), sg.FilesBrowse()], [sg.OK(), sg.Cancel()]]).Read()
print(values['_FILES_'].split(';'))
[ EDIT May 2022 ]
OK, well, here we are again at SO with the all-too-familiar problem of nothing dies here.... everything stays around, forever, including old problems with old solutions and are no longer a "problem".
While this is an interesting solution, it's from April 2019, only 9 months from the initial launch of PySimpleGUI. This answer is ancient, it works, but it's teaching bad conventions and approaches.
This discussion uses the non-PEP8 popup
calls, it's using the Window.Layout
method which should not be used, and the key naming conventions recommended by the PySimpleGUI project now don't match.
I didn't know PEP8 existed when naming the original popup calls and it took a while to get aliases for all of them created that do adhere to PEP8 conventions once I figured out that rather grave error.
The PySimpleGUI documentation and demo programs are kept up to date... these answers on StackOverflow are not. It's impossible to find all places on the internet where answers are posted and fix them. But the documentation and sample programs on GitHub are possible to be maintained...and they are.
One "problem" that arises with the strong desire for PySimpleGUI to be backward compatible and thus enable programs written in the first month PySimpleGUI was released is that it doesn't prohibit using calls that are no longer recommended.
The new answer
Ask on GitHub
The way I would answer this question today, in 2022, would be to first say please ask via an Issue on GitHub. Not just for this project, but for all projects, go to the project's home and ask the developers. When looking for answers, go THERE to find the answers. You may find an answer here, but it could come at a cost. Start with the project's documentation and then spread out from there.
"Googling it" is not the best approach to programming. It will lead you to old, possibly bad information. Their algorithm is stupid, you, reader, are not.
The popups
popup_get_file
is the PEP8 compliant name of the popup call and should be what's used. It now has a parameter called multiple_files
that when set to True
will allow your user to select more than 1 file. Check out the call reference tab in the main documentation for details - http://www.PySimpleGUI.org
The description you'll find of that parameter is:
if True, then allows multiple files to be selected that are returned with ';' between each filename
The Final Answer...
files = sg.popup_get_file('Unique File select', multiple_files=True)
This is how you would perform the operation today to get multiple files via a popup call.
Thank you for your attention
It's a long-winded edit, but it's an important topic in a very broad sense. I get wanting to ask the google-genie to get a quick answer, but quick answer isn't what makes solid product or even a good one.