当前位置: 首页>>代码示例>>Python>>正文


Python tkFileDialog.asksaveasfilename方法代码示例

本文整理汇总了Python中tkFileDialog.asksaveasfilename方法的典型用法代码示例。如果您正苦于以下问题:Python tkFileDialog.asksaveasfilename方法的具体用法?Python tkFileDialog.asksaveasfilename怎么用?Python tkFileDialog.asksaveasfilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkFileDialog的用法示例。


在下文中一共展示了tkFileDialog.asksaveasfilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_settings

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def save_settings(self):
        """Save current settings."""
        s = {key: self.settings[key].get() for key in self.settings}

        if self.store_last_settings:
            if not os.path.exists(self.default_path_to_pref):
                os.makedirs(self.default_path_to_pref)
            with open(os.path.join(self.default_path_to_pref,
                                   '_last_settings.json'), 'w') as f:
                f.write(json.dumps(s))
            self.store_last_settings = False
        else:
            path_to_pref = filedialog.asksaveasfilename(
                defaultextension='.json', filetypes=[("json files", '*.json')],
                initialdir=self.default_path_to_pref,
                title="Choose filename")
            with open(path_to_pref, 'w') as f:
                f.write(json.dumps(s)) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:20,代码来源:gui.py

示例2: save_grammar

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def save_grammar(self, filename=None):
        if not filename:
            ftypes = [('Chunk Gramamr', '.chunk'),
                      ('All files', '*')]
            filename = tkFileDialog.asksaveasfilename(filetypes=ftypes,
                                                      defaultextension='.chunk')
            if not filename: return
        if (self._history and self.normalized_grammar ==
            self.normalize_grammar(self._history[-1][0])):
            precision, recall, fscore = ['%.2f%%' % (100*v) for v in
                                         self._history[-1][1:]]
        elif self.chunker is None:
            precision = recall = fscore = 'Grammar not well formed'
        else:
            precision = recall = fscore = 'Not finished evaluation yet'

        out = open(filename, 'w')
        out.write(self.SAVE_GRAMMAR_TEMPLATE % dict(
            date=time.ctime(), devset=self.devset_name,
            precision=precision, recall=recall, fscore=fscore,
            grammar=self.grammar.strip()))
        out.close() 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:chunkparser_app.py

示例3: print_to_file

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def print_to_file(self, filename=None):
        """
        Print the contents of this C{CanvasFrame} to a postscript
        file.  If no filename is given, then prompt the user for one.

        @param filename: The name of the file to print the tree to.
        @type filename: C{string}
        @rtype: C{None}
        """
        if filename is None:
            from tkFileDialog import asksaveasfilename
            ftypes = [('Postscript files', '.ps'),
                      ('All files', '*')]
            filename = asksaveasfilename(filetypes=ftypes,
                                         defaultextension='.ps')
            if not filename: return
        (x0, y0, w, h) = self.scrollregion()
        self._canvas.postscript(file=filename, x=x0, y=y0,
                                width=w+2, height=h+2,
                                pagewidth=w+2, # points = 1/72 inch
                                pageheight=h+2, # points = 1/72 inch
                                pagex=0, pagey=0) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:24,代码来源:__init__.py

示例4: save_grammar

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def save_grammar(self, *args):
        filename = asksaveasfilename(filetypes=self.GRAMMAR_FILE_TYPES,
                                     defaultextension='.cfg')
        if not filename: return
        try:
            if filename.endswith('.pickle'):
                pickle.dump((self._chart, self._tokens), open(filename, 'w'))
            else:
                file = open(filename, 'w')
                prods = self._grammar.productions()
                start = [p for p in prods if p.lhs() == self._grammar.start()]
                rest = [p for p in prods if p.lhs() != self._grammar.start()]
                for prod in start: file.write('%s\n' % prod)
                for prod in rest: file.write('%s\n' % prod)
                file.close()
        except Exception, e:
            tkMessageBox.showerror('Error Saving Grammar',
                                   'Unable to open file: %r' % filename) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:20,代码来源:chart.py

示例5: save_raw

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def save_raw(self):
        self.status['text'] = _('Fetching data...')
        self.w.update_idletasks()

        try:
            data = companion.session.station()
            self.status['text'] = ''
            f = tkFileDialog.asksaveasfilename(parent = self.w,
                                               defaultextension = platform=='darwin' and '.json' or '',
                                               filetypes = [('JSON', '.json'), ('All Files', '*')],
                                               initialdir = config.get('outdir'),
                                               initialfile = '%s%s.%s.json' % (data.get('lastSystem', {}).get('name', 'Unknown'), data['commander'].get('docked') and '.'+data.get('lastStarport', {}).get('name', 'Unknown') or '', strftime('%Y-%m-%dT%H.%M.%S', localtime())))
            if f:
                with open(f, 'wt') as h:
                    h.write(json.dumps(data, ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8'))
        except companion.ServerError as e:
            self.status['text'] = str(e)
        except Exception as e:
            if __debug__: print_exc()
            self.status['text'] = unicode(e) 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:22,代码来源:EDMarketConnector.py

示例6: export

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def export(self):
        filename = asksaveasfilename(
            filetypes=(
                (_("JSON files"), "*.json"),
                (_("HTML files"), "*.html;*.htm"),
                (_("Text files"), "*.csv;*.txt"),
                (_("All files"), "*.*"),
            )
        )
        if filename == "":
            return
        ProcessCMD(["log", filename])
        ProcessCMD(["loglevel", str(100)])
        if ".json" in filename:
            ProcessCMD(["json"])
        elif ".csv" in filename:
            ProcessCMD(["csv"])
        elif ".htm" in filename:
            ProcessCMD(["html"])
        else:
            ProcessCMD(["table"])
        ProcessCMD(["loglevel", str(10)]) 
开发者ID:NeiroNx,项目名称:python-dvr,代码行数:24,代码来源:DeviceManager.py

示例7: menu_saveas

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def menu_saveas(self):
        if self.root_element is None:
            tkMessageBox.showwarning(None, "Cannot save empty configuration.")
        else:
            fname = tkFileDialog.asksaveasfilename()
            if len(fname) > 0:  # file was selected
                try:
                    with open(fname, "w") as handle:
                        write_json(self.root_element.serialize(), handle)
                except IOError:
                    tkMessageBox.showerror(None, "Failed to save config file.")
                else:
                    self.cfg_file_name.set(fname)
                    tkMessageBox.showinfo(
                        None, "Save successful:\n{}".format(self.cfg_file_name.get())
                    ) 
开发者ID:FowlerLab,项目名称:Enrich2,代码行数:18,代码来源:configurator.py

示例8: new_db

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def new_db(self, filename=''):
        """create a new database"""
        if filename == '':
            filename = filedialog.asksaveasfilename(
                initialdir=self.initialdir, defaultextension='.db',
                title="Define a new database name and location",
                filetypes=[("default", "*.db"), ("other", "*.db*"),
                           ("all", "*.*")])
        if filename != '':
            self.database_file = filename
            if os.path.isfile(filename):
                self.set_initialdir(filename)
                if messagebox.askyesno(
                   message='Confirm Destruction of previous Datas ?',
                   icon='question', title='Destroying'):
                    os.remove(filename)
            self.conn = Baresql(self.database_file)
            self.actualize_db() 
开发者ID:stonebig,项目名称:sqlite_bro,代码行数:20,代码来源:sqlite_bro.py

示例9: sav_script

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def sav_script(self):
        """save a script in a file"""
        active_tab_id = self.n.notebook.select()
        if active_tab_id != '':
            # get current selection (or all)
            fw = self.n.fw_labels[active_tab_id]
            script = fw.get(1.0, END)[:-1]
            filename = filedialog.asksaveasfilename(
                initialdir=self.initialdir, defaultextension='.db',
                title="save script in a sql file",
                filetypes=[("default", "*.sql"), ("other", "*.txt"),
                           ("all", "*.*")])
        if filename != "":
            self.set_initialdir(filename)
            with io.open(filename, 'w', encoding='utf-8') as f:
                if "你好 мир Artisou à croute" not in script:
                    f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
                f.write(script) 
开发者ID:stonebig,项目名称:sqlite_bro,代码行数:20,代码来源:sqlite_bro.py

示例10: exsav_script

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def exsav_script(self):
        """write script commands + top results to a log file"""
        # idea from http://blog.mp933.fr/post/2014/05/15/Script-vs.-copy/paste
        active_tab_id = self.n.notebook.select()
        if active_tab_id != '':
            # get current selection (or all)
            fw = self.n.fw_labels[active_tab_id]
            script = fw.get(1.0, END)[:-1]
            filename = filedialog.asksaveasfilename(
                initialdir=self.initialdir, defaultextension='.db',
                title="execute Script + output in a log file",
                filetypes=[("default", "*.txt"), ("other", "*.log"),
                           ("all", "*.*")])
        if filename == "":
            return
        self.set_initialdir(filename)
        with io.open(filename, 'w', encoding='utf-8') as f:
            if "你好 мир Artisou à croute" not in script:
                f.write("/*utf-8 tag : 你好 мир Artisou à croute*/\n")
            self.create_and_add_results(script, active_tab_id, limit=99, log=f)
            fw.focus_set()  # workaround bug http://bugs.python.org/issue17511 
开发者ID:stonebig,项目名称:sqlite_bro,代码行数:23,代码来源:sqlite_bro.py

示例11: export_csv_dialog

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def export_csv_dialog(self, query="--", text="undefined.csv", actions=[]):
        """export csv dialog"""
        # proposed encoding (we favorize utf-8 or utf-8-sig)
        encodings = ["utf-8", locale.getdefaultlocale()[1], "utf-16",
                     "utf-8-sig"]
        if os.name == 'nt':
            encodings = ["utf-8-sig", locale.getdefaultlocale()[1], "utf-16",
                         "utf-8"]
        # proposed csv separator
        default_sep = [",", "|", ";"]
        csv_file = filedialog.asksaveasfilename(
            initialdir=self.initialdir, defaultextension='.db', title=text,
            filetypes=[("default", "*.csv"), ("other", "*.txt"),
                       ("all", "*.*")])
        if csv_file != "":
            # Idea from (http://www.python-course.eu/tkinter_entry_widgets.php)
            fields = ['', ['csv Name', csv_file, 'r', 100], '',
                      ['column separator', default_sep],
                      ['Header line', True],
                      ['Encoding', encodings], '',
                      ["Data to export (MUST be 1 Request)",
                       (query), 'w', 100, 10]]

            create_dialog(("Export to %s" % csv_file), fields,
                          ("Export", export_csv_ok), actions) 
开发者ID:stonebig,项目名称:sqlite_bro,代码行数:27,代码来源:sqlite_bro.py

示例12: _save_crop

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def _save_crop(self):
        log.debug('crop bounds: %s', self._bounds)
        if self._bounds is None:
            return
        bounds = self.select_bounds
        # ext = '.%dx%d.png' % tuple(self._size)
        # tkFileDialog doc: http://tkinter.unpythonic.net/wiki/tkFileDialog
        save_to = tkFileDialog.asksaveasfilename(**dict(
            initialdir=self._save_parent_dir,
            defaultextension=".png",
            filetypes=[('PNG', ".png")],
            title='Select file'))
        if not save_to:
            return
        save_to = self._fix_path(save_to)
        # force change extention with info (resolution and offset)
        save_to = os.path.splitext(save_to)[0] + self._fileext_text.get()

        self._save_parent_dir = os.path.dirname(save_to)

        log.info('Crop save to: %s', save_to)
        self._image.crop(bounds).save(save_to)
        self._genfile_name.set(os.path.basename(save_to))
        self._gencode_text.set('d.click_image(r"%s")' % save_to) 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:26,代码来源:tkgui.py

示例13: validate_file_path

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def validate_file_path(self):

        if len(self.filePath.get()) < 1:
            path = tkFileDialog.asksaveasfilename(parent=self.master,defaultextension=".xml", initialfile="%s.xml" % self.getInitialFileName(), title="Save New Config", initialdir=self.getInitialFolder())
            self.filePath.set(path)
            
        if len(self.filePath.get()) < 1:
            
            tkMessageBox.showwarning(
                    "File path not specified",
                    "A file save path has not been specified, please try again or hit cancel to exit without saving.")
                
            return 0
            
        if self.originalPath != None and self.filePath.get() != self.originalPath and os.path.isfile(self.filePath.get()):                        
            result = tkMessageBox.askokcancel(
            "File Overwrite Confirmation",
            "Specified file path already exists, do you wish to overwrite?")
            if not result: return 0

        return 1 
开发者ID:PCWG,项目名称:PCWG,代码行数:23,代码来源:base_dialog.py

示例14: ExportReport

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def ExportReport(self):

            preferences = Preferences.get()

            if self.analysis is None:
                Status.add("ERROR: Analysis not yet calculated", red=True)
                return


            try:

                fileName = tkFileDialog.asksaveasfilename(parent=self.root,
                                                          defaultextension=".xls",
                                                          initialfile="report.xls",
                                                          title="Save Report",
                                                          initialdir=preferences.analysis_last_opened_dir())

                self.analysis.report(fileName)
                Status.add("Report written to %s" % fileName)

            except ExceptionHandler.ExceptionType as e:

                ExceptionHandler.add(e, "ERROR Exporting Report") 
开发者ID:PCWG,项目名称:PCWG,代码行数:25,代码来源:root.py

示例15: ExportPDM

# 需要导入模块: import tkFileDialog [as 别名]
# 或者: from tkFileDialog import asksaveasfilename [as 别名]
def ExportPDM(self):

            preferences = Preferences.get()

            if self.analysis is None:
                Status.add("ERROR: Analysis not yet calculated", red=True)
                return

            try:

                fileName = tkFileDialog.asksaveasfilename(parent=self.root,
                                                          defaultextension=".xml",
                                                          initialfile="power_deviation_matrix.xml",
                                                          title="Save Report",
                                                          initialdir=preferences.analysis_last_opened_dir())

                self.analysis.report_pdm(fileName)
                Status.add("Power Deviation Matrix written to %s" % fileName)

            except ExceptionHandler.ExceptionType as e:

                ExceptionHandler.add(e, "ERROR Exporting Report") 
开发者ID:PCWG,项目名称:PCWG,代码行数:24,代码来源:root.py


注:本文中的tkFileDialog.asksaveasfilename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。