Simple easygui File Dialogs

Did you know that you can have a file-open or -save dialog in just 2 lines of Python? Stephen Ferg’s excellent easygui module makes it possible. No other modules are needed, easygui is cross-platform. See also the enterbox example.

Two lines of code:

import easygui
fileNameAndPath = easygui.fileopenbox(title = "Choose your file", argInitialFile = "*.txt")

Resulting dialog with a custom title and a ‘*.txt’ file filter:

Full code:

# fileopenbox example, 20070619 Ian Ozsvald
# documentation from: http://www.ferg.org/easygui/easygui.txt
# For file-opening:
# fileopenbox(title=None, argInitialFile=None):
# For file-saving:
# filesavebox(title=None, argInitialFile=None)
import easygui
fileNameAndPath = easygui.fileopenbox(title = "Choose your file", argInitialFile = "*.txt")
# fileNameAndPath will look like
# 'C:/easygui/someDocument.txt'
# if the user selects a file
# or None if the user presses Cancel
print fileNameAndPath

To see easygui’s fileopenbox, filesavebox, choicebox, enterbox and ynbox in action and learn how to write a Python program from scratch, visit: Python 101 - easygui and csv.

4 Responses to “Simple easygui File Dialogs”

  1. polaar Says:

    See also EasyDialogs:
    http://www.averdevelopment.com/python/EasyDialogs.html

    “EasyDialogs for Windows is a ctypes based emulation of the EasyDialogs module included in the Python distribution for Mac.”

  2. Administrator Says:

    Interesting, I get to learn something new everytime I make a post like this :-) Thanks for the link.
    Ian.

  3. ShowMeDo Blog » Blog Archive » Simple easygui User Input (enterbox) Says:

    [...] Following on from the fileopenbox example I’ll show you how to replace raw_input with an input-dialog in 2 lines of Python, using Stephen Ferg’s easygui module. No other modules are needed, easygui is cross-platform. [...]

  4. ShowMeDo Blog » Blog Archive » Simple easygui Yes/No Input (boolbox) Says:

    [...] Simple Yes/No queries give us a simple way of asking the user for confirmation. Stephen Ferg’s easygui makes this easy with the ynbox. No other modules are needed, easygui is cross-platform. This follows-on from the enterbox and fileopenbox examples. [...]

Leave a Reply

You must be logged in to post a comment.