简体   繁体   English

如何使用 tkinter 在 python 中 select 多个文件或整个文件夹(显示其中包含的所有文件的名称)?

[英]How to select multiple files or an entire folder(display names of all the files it contains) in python using tkinter?

I have written a code to display the contents of a file using tkinter askopenfile() method.我编写了一个代码来使用 tkinter askopenfile() 方法显示文件的内容。 Now I need to select an entire folder(directory) and print the names of the files it contains or select multiple files.现在我需要 select 整个文件夹(目录)并打印它包含的文件的名称或 select 多个文件。

I'm new to the concepts of tkinter and having a difficult time understanding this.我对 tkinter 的概念不熟悉,很难理解这一点。 Is there any method to do this?有什么方法可以做到这一点吗?

Thanks in advance.提前致谢。

I assume you are using python 2, so here you go:我假设您使用的是 python 2,所以这里是 go:

from Tkinter import *
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog

root = Tk()
root.filename = tkFileDialog.askopenfilename(initialdir = "/")

print(root.filename)

Hope this helps!希望这可以帮助!

FYI: I would suggest you update to python 3. Python 2 has been sun-setted(on January 1st, 2020).仅供参考:我建议您更新到 python 3。Python 2 已日落(2020 年 1 月 1 日)。

暂无
暂无

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

相关问题 在 Tkinter 中使用 askdirectory() 选择文件夹时显示所有文件 - Display all the files while selecting a folder using askdirectory() in Tkinter 如何在具有不同名称的文件夹中加载 all.txt 文件 - Python - How to load all .txt files in a folder with separate names - Python 如何使用 python 中 tsv 文件中的名称从一个文件夹中打开多个文件? - How to open multiple files from a folder using the names in tsv file in python? 如何使用python 3检查文件夹是否包含文件 - How to check to see if a folder contains files using python 3 使用 Tkinter 显示当前文件夹的所有 PNG 文件 - Display All PNG Files of Your Current Folder with Tkinter 如何使用 python 真正删除文件夹中的所有文件和 Windows 上的文件夹? - How to really delete all files in a folder and the folder on Windows using python? Python为一个文件夹中的所有文件夹创建多个zip文件 - Python to create multiple zip files for all in a folder 如何在多个子目录中找到具有相同扩展名的所有文件并使用 python 将它们移动到单独的文件夹中? - How can find all files of the same extension within multiple subdirectories and move them to a seperate folder using python? Python,easyGUI和sqlite3:使用python读取一个文件夹或多个文件夹中的文件,然后将文件夹名称和文件名添加到数据库 - Python, easyGUI and sqlite3: Using python to read files in one folder or multiple folder, then adding the folder names and filenames to database 使用名称列表在python中打开多个文件 - using a list of names to open multiple files in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM