I was looking for a "file selection widget", basically a Text field that would open an OS-specific file selection dialog and return the path of the selected file as a string value. I could not find that. Is that because it doesn't exist? And if so, would this be possible/doable? I'm not sure how this could be done in some OS-independant way, though.
I have used this gist as a basis for developing similar widgets in the past, I am not hugely familiar with tkinter but managed to get something to achieve what you need.
https://codereview.stackexchange.com/questions/162920/file-selection-button-for-jupyter-notebook
I ended up linking together this button and a text field to display the returned filename.
@andymcarter i've just tested this on macOS and JupyterLab. I get a Python process started with a file selection dialog, but it's not immediately in the foreground and will not close after selecting files. So I have to kill it. Also, I'm totally not sure Tk is the way to go... ;)
It works well, but only for local notebooks. It does not work when the notebook runs remotely. And for remote files.
I'm not sure how this could be done in some OS-independant way, though.
Here is an existing OS-independent implementation: https://pypi.org/project/ipyfilechooser/
There's something similar implemented already as FileUpload that returns the contents of the file. Would it be straightforward to make a version of this that just returns the path to the file? Would be great to be able to make another similar dialog box pop up for saving a file, where you can navigate to a path and select or name the file to save to. I have not found the Tk solutions to play nice with ipy notebooks on as Mac.
I'm looking for something similar, I want to make a locally running Voila app and I'd like to have a widget that lets the user specify a folder or file where I can access the full path.
I've been trying to do this too
Most helpful comment
There's something similar implemented already as FileUpload that returns the contents of the file. Would it be straightforward to make a version of this that just returns the path to the file? Would be great to be able to make another similar dialog box pop up for saving a file, where you can navigate to a path and select or name the file to save to. I have not found the Tk solutions to play nice with ipy notebooks on as Mac.