directory/file dialog#

GUI dialogs to choose files and directories using Tkinter

This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.

copyright:

Copyright 2015-2022 Matthias Cuntz, see AUTHORS.rst for details.

license:

MIT License, see LICENSE for details.

The following functions are provided

directory_from_gui([initialdir, title])

Opens dialog to one select directory

directories_from_gui([initialdir, title])

Open dialog to select several directories

file_from_gui([initialdir, title, multiple])

Wrapper for files_from_gui() with multiple=False, i.e. open dialog to select one file.

files_from_gui([initialdir, title, multiple])

Open dialog to select one or several files

History
  • Written Jun 2014 by Matthias Cuntz (mc (at) macu (dot) de)

  • Added directories_from_gui, Oct 2015, Matthias Cuntz

  • Using numpy docstring format, May 2020, Matthias Cuntz

  • Port to pyjams, Jan 2022, Matthias Cuntz

directories_from_gui(initialdir='.', title='Choose one or several directories')[source]#

Open dialog to select several directories

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)

  • title (str, optional) – Title of GUI (default: ‘Choose one or several directories’)

Returns:

Selected directories

Return type:

list

Examples

if not direcs:
    direcs = directories_from_gui()
    if not direcs:
        raise ValueError('Error: no directories given.')
directory_from_gui(initialdir='.', title='Choose directory')[source]#

Opens dialog to one select directory

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)

  • title (str, optional) – Title of GUI (default: ‘Choose directory’)

Returns:

Selected directory

Return type:

str

Examples

if not idir:
    idir = directory_from_gui()
    if not idir:
        raise ValueError('Error: no directory given.')
file_from_gui(initialdir='.', title='Choose file', multiple=False)[source]#

Wrapper for files_from_gui() with multiple=False, i.e. open dialog to select one file

Examples

if not file:
    file = file_from_gui()
    if not file:
        raise ValueError('Error: no input file given.')
files_from_gui(initialdir='.', title='Choose file(s)', multiple=True)[source]#

Open dialog to select one or several files

Parameters:
  • initialdir (str, optional) – Initial directory, in which opens GUI (default: ‘.’)

  • title (str, optional) – Title of GUI (default: ‘Choose file(s)’)

  • multiple (bool, optional) – Allow selection of multiple files if True (default), else it is only possible to select one single file.

Returns:

Selected file(s)

Return type:

list

Notes

It always returns a list even with multiple=False.

Examples

if not files:
    files = files_from_gui()
    if not files:
        raise ValueError('Error: no input file(s) given.')