The GTK framework has the "Filechooserdialog" which is a complete window to browse the file system, and allows either the choice of an existing file (or directory) ("open" action), or the user to write a new name ("save" action").
Since your question, unlike the practices indicated, has nothing of your code, I also have no way to give an example of use (without writing an entire, functional program).
The Filechooser documentation as used by Python is here:
http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#filechooserdialog
basically, the call to create the dialogue is:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk
...
dialog = gtk.FileChooserDialog(
title="Please choose a file", window=sua_janela_principal_,
action=gtk.FileChooserAction.OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL,
gtk.STOCK_OPEN, gtk.ResponseType.OK))
)
After you build the dialog and configure the desired parameters, call the method run
: the current thread of your program pauses while the dialog is used by the user - after the user chooses and confirms a file, check which name was chosen by calling:
nome = dialog.get_filename()
dialog.destroy()
In the above url there is a complete program using the dialog with more details (what to do in case the user cancels the action, for example)
What do you mean by "open a folder"? Display on screen what are the files? Tree-view these files?
– Jefferson Quesado
@Filipesantos No, it’s not clear. Opening the folder is very vague, by the way, technically speaking, there is no such thing as opening the folder. I think you mean you want to show the contents of the folder by the system file manager.
– Jéf Bueno
@Filipesantos which graphical interface are you using? Currently we can only do one
ls
, at most, and return the list of files inside the folder– Jefferson Quesado
Aaaah good, you want to open one dialog of save, if I’m not mistaken the graphical interface (of the operating system) gives you some option. By the way, when @Jeffersonquesado asked which graphical interface you are using he spoke the graphical interface of the xD operating system
– Jéf Bueno
@Filipesantos Here is the starting point for what you want to do (http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#filechooserdialog)
– Jéf Bueno
Now I understand the question.
– Jefferson Quesado
I thought to run a cmd in the terminal by python like Nautilus to open the folder, or xdg-open what they think?
– HelloWorld
people - it’s not so hard -all frameworks for graphics programs have something like that already ready. I don’t know if before the question was edited it was clear that the AP was using GTK - if it wasn’t, that’s what had to be checked. But since we know that uses GTK just see the documentation there - it would be analogous if it were Tkinter, Qt5, win32com , etc... "open a separate program using Nautilus" would be quite bizarre.
– jsbueno
@jsbueno this was only clear in the second revision
– Jefferson Quesado