使用TK inter模块导入多个文件

时间:2014-05-11 18:46:11

标签: python python-2.7 tkinter

我开发了一种将vcf文件导出为ex​​cel的算法。 现在我想创建一个用户界面,其中包含一个选项,可以使用浏览按钮将多个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做到这一点吗?

亲切的问候,

格伦

1 个答案:

答案 0 :(得分:0)

如果要选择多个文件,请将s添加到askopenfilename

fnames = askopenfilenames()

print(fnames.split())