我正在使用 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"]
另一种选择可能是使用 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是不可能的。您可以做的是重用来自 easygui 的代码(参见第 1700 行)并稍微修改它以使用askopenfilenames
而不是askopenfilename
.