我开发了一种将vcf文件导出为excel的算法。 现在我想创建一个用户界面,其中包含一个选项,可以使用浏览按钮将多个vcf文件导入到1个条目中。
class MyFrame(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("Vcf to excel converter")
self.geometry("300x200")
self.master.rowconfigure(5, weight=1)
self.master.columnconfigure(5, weight=1)
self.grid(sticky=W+E+N+S)
self.entry=Entry(self)
self.entry.grid(row=2, column=1)
self.button = Button(self, text="Browse", command=self.load_file, width=10)
self.button.grid(row=2, column=6, sticky=E)
self.button1= Button(self, text="Convert", width=10)
self.button1.grid(row=100, column=3, sticky=E)
def load_file(self):
fname = askopenfilename(filetypes=(("Vcards", "*.vcf"),
))
if fname:
try:
print("""here it comes: self.settings["template"].set(fname)""")
except: # <- naked except is a bad idea
showerror("Open Source File", "Failed to read file\n'%s'" % fname)
return
MyFrame().mainloop()
上面你看到1 vcf文件的算法。 我们的想法是在这个brwoser中选择同一目录中的多个文件到一个条目中,并将此条目导出到如下列表:
[[&#34; d:\文件\ 1.vcf&#34],[[&#34; d:\文件\ 2.vcf&#34;],[&#34; d:\文件\ 3.vcf&#34;] ...]
所以我希望此列表中的完整目录将其用于我的功能。 现在有人如何用Tkinter做到这一点吗?
亲切的问候,
格伦
答案 0 :(得分:0)
如果要选择多个文件,请将s
添加到askopenfilename
:
fnames = askopenfilenames()
print(fnames.split())