Python tkFileDialog 模块,asksaveasfile() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用tkFileDialog.asksaveasfile()

项目:Cryptokey_Generator    作者:8BitCookie    | 项目源码 | 文件源码
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)
项目:SceneDensity    作者:ImOmid    | 项目源码 | 文件源码
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)
项目:BeachedWhale    作者:southpaw5271    | 项目源码 | 文件源码
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)
项目:MACE-AL    作者:julmaxi    | 项目源码 | 文件源码
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()
项目:SUTDAnnotator    作者:jiesutd    | 项目源码 | 文件源码
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()
项目:ForcedAlignment    作者:2017fandrei    | 项目源码 | 文件源码
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
项目:DualFisheye    作者:ooterness    | 项目源码 | 文件源码
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.
项目:DualFisheye    作者:ooterness    | 项目源码 | 文件源码
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.')
项目:ds_homework1    作者:abachinskyi    | 项目源码 | 文件源码
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()
项目:sendobox    作者:sendobox    | 项目源码 | 文件源码
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')