我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用tkFileDialog.askopenfilenames()。
def openfiles(self): """ Open dialog for selecting CIF files""" options = {} options['initialdir'] = '{0}'.format(os.path.expanduser('~')) options['filetypes'] = [('all files', '.*'), ('CIF files', '.cif')] options['title'] = 'CIF files for processing' options['defaultextension'] = '.cif' filenames = tkFileDialog.askopenfilenames(parent=self.parent, **options) filelist = self.parent.tk.splitlist(filenames) for file in filelist: if os.path.normpath(file) not in self.filenames: self.filenames.append(os.path.normpath(file)) self.filebox.insert(tk.END, os.path.basename(file) ) if len(self.filenames) > 0: self.clearbutton.configure(state='normal')
def combineFiles(event): fileNames = tkFileDialog.askopenfilenames() fileNameTokens = fileNames[0].split("/") relFileName = fileNameTokens[len(fileNameTokens)-1] outFileName = "combined_" + "combine" + str(len(fileNames)) print(outFileName) combineCommand = [] combineCommand.append("cat") fileNameList = list(fileNames) for f in fileNameList: combineCommand.append(f) dir_path = "combine/" if not os.path.isdir("./" + dir_path): os.makedirs("combine/") outFile = open(os.path.join(dir_path, outFileName + ".txt"), "w") result = subprocess.call(combineCommand, stdout=outFile) print(result) outFile.close()
def choosestruct(self, initialdir): p = Tkinter.Tk() p.withdraw() slist = [] structures = tkFileDialog.askopenfilenames( parent=p, initialdir=initialdir, title="Choose structure files", filetypes=[("pdb files", ".pdb")] ) # WARNING! askopenfilenames: # on Windows, it returns a string. On Linux, it returns a list. if type(structures) is list or type(structures) is tuple: # if on Linux for i in structures: slist.append(i) elif len(structures) > 1: # if on Windows and anything was chosen structures = structures.split(" ") for i in structures: slist.append(i) else: # if "cancel" pass return slist
def calFrequency(event): files = tkFileDialog.askopenfilenames() fileList = list(files) print(fileList) freqCommand = [] freqCommand.append("python") freqCommand.append("./scripts/frequency.py") for f in fileList: freqCommand.append(f) outFile = open("frequency_output.txt", "w") result = subprocess.call(freqCommand, stdout=outFile) outFile.close() # open a new window to view the frequency output
def multiFiles(self): ftypes = [('ann files', '.ann')] filez = tkFileDialog.askopenfilenames(parent=self.parent, filetypes = ftypes, title='Choose a file') if len(filez) < 2: tkMessageBox.showinfo("Monitor Error", "Selected less than two files!\n\nPlease select at least two files!") else: result_matrix = generate_report_from_list(filez) self.ChildWindow(filez, result_matrix)
def compareTwoFiles(self): ftypes = [('ann files', '.ann')] filez = tkFileDialog.askopenfilenames(parent=self.parent, filetypes = ftypes, title='Choose a file') if len(filez) != 2: tkMessageBox.showinfo("Compare Error", "Please select exactly two files!") else: f = tkFileDialog.asksaveasfile(mode='w', defaultextension=".tex") write_result = compareBoundary(filez[0],filez[1],f) if write_result: tkMessageBox.showinfo("Latex Generate", "Latex file generated successfully!\n\nSaved to "+ f.name) # import os # os.system("pdflatex "+ f.name) else: tkMessageBox.showinfo("Latex Error", "Latex generated Error, two files don't have same sentence number!") f.close()
def get_filenames(): Tk().withdraw() print("Initializing Dialogue... \nPlease select a file.") tk_filenames = askopenfilenames(initialdir=os.getcwd(), title='Please select one or more files') filenames = list(tk_filenames) return filenames