Search code examples
pythoneasyguifileopenpicker

Python EasyGUI fileopenbox() filter more items


I want to set EasyGUI fileopenbox() to filter more filetypes and not just one.

Here below is a code I tried but instead of custom files selection i get more selections.

file=easygui.fileopenbox(title='Select image', filetypes=('*.png', '*.jpg'))

How to fix this?


Solution

  • From docs

    About the “filetypes” argument

    If specified, it should contain a list of items, where each item is either:

    • a string containing a filemask # e.g. “*.txt”

    • a list of strings, where all of the strings except the last one are filemasks (each beginning with “.”, such as “.txt” for text files, “*.py” for Python files, etc.). and the last string contains a filetype description

    EXAMPLE:

    filetypes = ["*.css", ["*.htm", "*.html", "HTML files"] ]

    So corresponding to your usecase, you can write:

    file=easygui.fileopenbox(title='Select image', filetypes=[["*.png", "*.jpg", "Image files"]])