【问题标题】:Python: easygui, how to select multiple files?Python:easygui,如何选择多个文件?
【发布时间】:2018-08-22 19:08:11
【问题描述】:

我正在使用 fileopenbox() 并且我想在 windows 框打开时选择我拥有的所有文本文件。我试过按 shift 或 ctrl + A,但没用。

openfile = fileopenbox("Welcome", "COPR", filetypes= "*.txt")

【问题讨论】:

    标签: python easygui


    【解决方案1】:

    如果在参数中包含 multiple=True,则可以选择多个文件:

    openfiles = fileopenbox("Welcome", "COPR", filetypes= "*.txt", multiple=True)
    

    请注意,现在 fileopenbox 将返回的不是字符串,而是一个字符串列表,例如:

    ["foo.txt", "Hello.txt", "mytxt.txt"]

    【讨论】:

    • easygui 至少从 2002 年就已经存在,并且它的许多早期版本中的 fileopenbox() 函数不支持 muliple 关键字参数(尽管对它的支持很容易添加)。
    【解决方案2】:

    另一种选择可能是使用 tkinter,如下所示(python 3.x):

    import tkinter as tk from tkinter import filedialog root = tk.Tk() root.withdraw() files = filedialog.askopenfilenames(parent=root, initialdir="/", title='Please select files')

    【讨论】:

      【解决方案3】:

      easygui 无法做到这一点。你可以做的是重用the code from easygui(见第1700行)并稍微修改它以使用askopenfilenames而不是askopenfilename

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多