在tkinter中打开多个文件名并将文件名添加到列表中 [英] open multiple filenames in tkinter and add the filesnames to a list
本文介绍了在tkinter中打开多个文件名并将文件名添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的是选择多个文件 使用tkinter文件对话框 然后将这些项目添加到列表中. 之后,我想使用列表进行处理 每个文件一个接一个.
what I want to do is to select multiple files using the tkinter filedialog and then add those items to a list. After that I want to use the list to process each file one by one.
#replace.py
import string
def main():
#import tkFileDialog
#import re
#ff = tkFileDialog.askopenfilenames()
#filez = re.findall('{(.*?)}', ff)
import Tkinter,tkFileDialog
root = Tkinter.Tk()
filez = tkFileDialog.askopenfilenames(parent=root,title='Choose a file')
现在,我可以选择多个文件, 但我不知道如何将这些文件名添加到列表中. 有什么想法吗?
Now, I am able to select multiple files, but I dont know how to add those filenames to the list. any ideas?
推荐答案
askopenfilenames
返回一个字符串而不是一个列表,该问题仍然在
askopenfilenames
returns a string instead of a list, that problem is still open in the issue tracker, and the best solution so far is to use splitlist
:
import Tkinter,tkFileDialog
root = Tkinter.Tk()
filez = tkFileDialog.askopenfilenames(parent=root,title='Choose a file')
print root.tk.splitlist(filez)
这篇关于在tkinter中打开多个文件名并将文件名添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文