【发布时间】:2018-08-22 19:08:11
【问题描述】:
我正在使用 fileopenbox() 并且我想在 windows 框打开时选择我拥有的所有文本文件。我试过按 shift 或 ctrl + A,但没用。
openfile = fileopenbox("Welcome", "COPR", filetypes= "*.txt")
【问题讨论】:
我正在使用 fileopenbox() 并且我想在 windows 框打开时选择我拥有的所有文本文件。我试过按 shift 或 ctrl + A,但没用。
openfile = fileopenbox("Welcome", "COPR", filetypes= "*.txt")
【问题讨论】:
如果在参数中包含 multiple=True,则可以选择多个文件:
openfiles = fileopenbox("Welcome", "COPR", filetypes= "*.txt", multiple=True)
请注意,现在 fileopenbox 将返回的不是字符串,而是一个字符串列表,例如:
["foo.txt", "Hello.txt", "mytxt.txt"]
【讨论】:
easygui 至少从 2002 年就已经存在,并且它的许多早期版本中的 fileopenbox() 函数不支持 muliple 关键字参数(尽管对它的支持很容易添加)。
另一种选择可能是使用 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')
【讨论】:
easygui 无法做到这一点。你可以做的是重用the code from easygui(见第1700行)并稍微修改它以使用askopenfilenames而不是askopenfilename。
【讨论】: