简体   繁体   English

Python EasyGUI fileopenbox() 过滤更多项目

[英]Python EasyGUI fileopenbox() filter more items

I want to set EasyGUI fileopenbox() to filter more filetypes and not just one.我想设置 EasyGUI fileopenbox()来过滤更多的文件类型,而不仅仅是一个。

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?如何解决这个问题?

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 # eg “*.txt”包含文件掩码的字符串 # 例如“*.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.).字符串列表,其中除最后一个之外的所有字符串都是文件掩码(每个字符串都以“ .”开头,例如“ .txt”表示文本文件,“*.py”表示 Python 文件等)。 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"]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM