我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用tkFileDialog.asksaveasfile()。
def saveBox( self, title=None, fileName=None, dirName=None, fileExt=".txt", fileTypes=None, asFile=False): self.topLevel.update_idletasks() if fileTypes is None: fileTypes = [('all files', '.*'), ('text files', '.txt')] # define options for opening options = {} options['defaultextension'] = fileExt options['filetypes'] = fileTypes options['initialdir'] = dirName options['initialfile'] = fileName options['title'] = title if asFile: return filedialog.asksaveasfile(mode='w', **options) # will return "" if cancelled else: return filedialog.asksaveasfilename(**options)
def save_predictions(self): f = tkFileDialog.asksaveasfile(mode='w') for sent_preds in self.annotation_state.state.get_current_predictions(): f.write("\n".join(map(lambda t: "\t".join(t), sent_preds))) f.write("\n\n") f.close()
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 htmlFile(): global html_file # Needed to modify global copy of html_file html_f1=tkFileDialog.asksaveasfile(mode=u'w',defaultextension=u".html") if html_f1 is None: # asksaveasfile return `None` if dialog closed with "cancel". return html_file=html_f1.name # text2save=str(text.get(0.0,END)) # html_f1.write(text2save) html_f1.close print html_file
def save_config(self, filename=None): if filename is None: file_obj = tkFileDialog.asksaveasfile() if file_obj is None: return else: file_obj = open(filename, 'w') try: save_config(file_obj, self.lens1, self.lens2) except: tkMessageBox.showerror('Config save error', traceback.format_exc()) # Render and save output in various modes.
def _render_generic(self, render_type, render_size=1024): # Popup asks user for output file. file_obj = tkFileDialog.asksaveasfile(mode='wb') # Abort if user clicks 'cancel'. if file_obj is None: return # Proceed with rendering... self._set_status('Rendering image: ' + file_obj.name, 'wait') try: panorama = self._create_panorama() render_func = getattr(panorama, render_type) render_func(render_size).save(file_obj) self._set_status('Done!') except: tkMessageBox.showerror('Render error', traceback.format_exc()) self._set_status('Render failed.')
def save_command(self): file = tkFileDialog.asksaveasfile(mode='w') if file != None: # slice off the last character from get, as an extra return is added data = self.textPad.get('1.0', END + '-1c') file.write(data) file.close()
def write_txt(username=None, password=None, start_date=None, end_date=None, aoi=None, platform=None, max_cloud_cover=None, download_path=None, image_id=None, download_options=None, image_path=None, preprocessing_options=None): config_file = tkFileDialog.asksaveasfile(mode='w', defaultextension=".txt", filetypes=(('Text','*.txt'),("All Files", "*.*"))) if username: config_file.write(username+'\n') else: config_file.write('\n') if password: config_file.write(password+'\n') else: config_file.write('\n') if start_date: config_file.write(start_date+'\n') else: config_file.write('\n') if end_date: config_file.write(end_date+'\n') else: config_file.write('\n') if aoi: config_file.write(aoi+'\n') else: config_file.write('\n') if platform: config_file.write(platform+'\n') else: config_file.write('\n') if max_cloud_cover: config_file.write(max_cloud_cover+'\n') else: config_file.write('\n') if download_path: config_file.write(download_path+'\n') else: config_file.write('\n') if image_id: config_file.write(image_id+'\n') else: config_file.write('\n') if download_options: config_file.write(download_options+'\n') else: config_file.write('\n') if image_path: config_file.write(image_path+'\n') else: config_file.write('\n') if preprocessing_options: config_file.write(preprocessing_options+'\n') else: config_file.write('\n')