0

I am starting to look into Python from a learning perspective and I am finding it nice and easy after Java.

I am currently looking at working with files and I am using the 'with open()' command to make use of the open file only whilst the program is running.

However, all the tutorials I seem to come across only ever seem to hard code either a filename or file path into the open() command.

In Python or any of its libraries - does anyone know of a command I can use to allow the user a pop-up window to navigate and select where the file lives?

Kind Regards

Paul Harper
  • 51
  • 2
  • 7
  • The word you are looking for is "GUI": "Graphical User Interface". – Jongware Jul 23 '18 at 12:57
  • I've never actually needed it, but you want a GUI. Easiest way is probably through `tkinter`. With this, you can design simple GUI which will return the file name / path needed for the `open()` command. – Mathieu Jul 23 '18 at 12:57
  • You either want something like `zenity` or a proper GUI framework like Qt which provides a `QFileDialog` class to deal with that. – Giacomo Alzetta Jul 23 '18 at 12:58

1 Answers1

0

Try using tkinter. tkinter is Python's de-facto standard GUI (Graphical User Interface) package. I will show an example

Either you can ask with this:

  • a_var = input('select directory of the file')

and then use the a_var to use the directory provided by the user

or

  • Use tkinter to ask the user to browse to the needed location
gsa
  • 790
  • 1
  • 8
  • 20
  • I completely disagree that it is "de facto standard". tkinter is almost **never** used. The only advantage of tkinter is that it comes bundled with python (most of the time. E.g. on Ubuntu they are on separate packages and hence you don't even have this advantage). The most common frameworks are probably GTK and Qt. – Giacomo Alzetta Jul 23 '18 at 12:59
  • 1
    Tkinter is used a ton... tcl more so... – gbtimmon Jul 23 '18 at 13:04