[英]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.