tkinter选择多文件对话框

本例展示tkinter实现选择多文件对话框,并可以选择文件类型。

from tkinter import Tk ,filedialog
root=Tk()
root.withdraw()
cur=filedialog.askopenfilenames(filetypes=[('text files', '.txt'),('pythonfiles',('.py','.pyw'))])
if cur:
    print(cur)
else:
    print('你没有选择任何文件')

桌面没有文本,试试效果: 

放一个txt到桌面试试效果:

放两个python文件试试:

切换到选择路径下按住ctrl并鼠标多选规定的文件类型后,结果cur是一个包含所选择的文件路径的元组。如下图:

猜你喜欢

转载自blog.csdn.net/qq_24499417/article/details/85222048