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


Python filedialog.asksaveasfilename方法代码示例

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


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

示例1: save_settings

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog 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_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_log():
        # 获取路径
        filename = asksaveasfilename(filetypes=[('比赛记录', '*.zlog')])
        if not filename:
            return

        if not filename.endswith('.zlog'):
            filename += '.zlog'

        # 写入比赛记录
        widget_off()
        try:
            with open(filename, 'wb') as f:
                f.write(zlib.compress(pickle.dumps(MATCH_LOG), -1))
        except Exception as e:
            showerror(type(e).__name__, str(e))
        widget_on()

    # 清空存储区 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:21,代码来源:5.visualize.py

示例3: save_file_as

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_file_as(self, file_path=None):
        # If there is no file path specified, prompt the user with a dialog which
        # allows him/her to select where they want to save the file
        if file_path is None:
            file_path = filedialog.asksaveasfilename(
                filetypes=(
                    ("Text files", "*.txt"),
                    ("Prolog files", "*.pl *.pro"),
                    ("All files", "*.*"),
                )
            )

        try:

            # Write the Prolog rule editor contents to the file location
            with open(file_path, "wb") as file:
                self.write_editor_text_to_file(file)
                self.file_path = file_path
                return "saved"

        except FileNotFoundError:
            return "cancelled" 
开发者ID:photonlines,项目名称:Python-Prolog-Interpreter,代码行数:24,代码来源:editor.py

示例4: save_grammar

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog 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'):
                with open(filename, 'wb') as outfile:
                    pickle.dump((self._chart, self._tokens), outfile)
            else:
                with open(filename, 'w') as outfile:
                    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: outfile.write('%s\n' % prod)
                    for prod in rest: outfile.write('%s\n' % prod)
        except Exception as e:
            tkinter.messagebox.showerror('Error Saving Grammar',
                                   'Unable to open file: %r' % filename) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:20,代码来源:chartparser_app.py

示例5: print_to_file

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def print_to_file(self, filename=None):
        """
        Print the contents of this ``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: str
        :rtype: None
        """
        if filename is None:
            from tkinter.filedialog 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,代码来源:util.py

示例6: save_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_log():
        # 获取路径
        filename = asksaveasfilename(filetypes=[('比赛记录', '*.zlog')])
        if not filename:
            return

        if not filename.endswith('.zlog'):
            filename += '.zlog'

        # 写入比赛记录
        widget_off()
        try:
            with open(filename, 'wb') as f:
                f.write(zlib.compress(pickle.dumps(MATCH_LOG), -1))
        except Exception as e:
            showerror('%s: %s' % (self.name, type(e).__name__), str(e))
        widget_on()

    # 清空存储区 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:21,代码来源:6.glory_of_mankind.py

示例7: save_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_log():
        # 获取路径
        filename = asksaveasfilename(filetypes=[('比赛记录', '*.clog')])
        if not filename:
            return

        if not filename.endswith('.clog'):
            filename += '.clog'

        # 写入比赛记录
        widget_off()
        try:
            match_interface.save_compact_log(MATCH_LOG, filename)
        except Exception as e:
            showerror('%s: %s' % (self.name, type(e).__name__), str(e))
        widget_on()

    # 清空存储区 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:20,代码来源:glory_of_mankind.py

示例8: save_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_log():
        # 获取路径
        filename = asksaveasfilename(filetypes=[('比赛记录', '*.clog')])
        if not filename:
            return

        if not filename.endswith('.clog'):
            filename += '.clog'

        # 写入比赛记录
        widget_off()
        try:
            match_interface.save_compact_log(MATCH_LOG, filename)
        except Exception as e:
            showerror(type(e).__name__, str(e))
        widget_on()

    # 清空存储区 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:20,代码来源:visualize.py

示例9: save_as

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_as(self, event):
        """
        It pops a asksaveasfilename window to save the contents of
        the text area.
        """
    
        filename = asksaveasfilename()
    
        if not filename: 
            return

        try:
            self.area.save_data_as(filename)
        except Exception:
            root.status.set_msg('It failed to save data.')
        else:
            root.status.set_msg('Data saved.') 
开发者ID:vyapp,项目名称:vy,代码行数:19,代码来源:io.py

示例10: export

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog 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

示例11: save_clicked

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def save_clicked(self):
		request = {	'component': 'draw',
					'draw': {'args': [None],
					'kwargs': {} } }
		try:
			request['draw']['kwargs']['power'] = float(self.power_var.get())
			if self.tilt_var.get(): request['draw']['kwargs']['tilt'] = float(self.tilt_var.get()) * np.pi
			else: request['draw']['kwargs']['tilt'] = None
			request['draw']['kwargs']['guess'] = float(self.guess_var.get())
		except ValueError: pass
		else:
			request['draw']['args'][0] = filedialog.asksaveasfilename(initialdir=self.get_save_dir(), initialfile='piecewise_polynomial.dat')
			if request['draw']['args'][0]:
				print ('\
Running trajectory drawing tool in a new process. Key bindings:\n\
shift: run optimization routine\n\
Z: save trajectory to data file\n\
T: toggle waypoint adjustment\n\
Path:', request['draw']['args'][0], end='\n\n')
				self.request_q.put(request) 
开发者ID:lindemer,项目名称:baldr,代码行数:22,代码来源:gui.py

示例12: cargarFB

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def cargarFB(self):

        try:
            rpta = msg.askyesno("Pregunta", "No se puede obtener información "+
                "de un video de facebook, desea continuar con la descarga?")

            if rpta:
                path = filedialog.asksaveasfilename()
                os.popen("facebook-dl.py {} hd {}".format(self.vista.url.get(),path))
                msg.showinfo("Mensaje", "Archivo descargado correctamente.")
                
        except:
            msg.showerror("Error", "El video no es público, o la url es inválida.")

        self.vista.button.config(state=NORMAL)
        self.vista.bvideo.config(state=NORMAL)
        self.vista.baudio.config(state=NORMAL)
        self.vista.bborrar.config(state=NORMAL)
        self.vista.config(cursor="") 
开发者ID:jjr4Programmer,项目名称:proyectoDownloader,代码行数:21,代码来源:Controlador.py

示例13: FileManager

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def FileManager(var):
    global fileExtension
    window = Tk()
    window.withdraw()
    if var != 2:
        availableFormats = [("Windows Text File", "*.txt")]
    else:
        availableFormats = [("Portable Network Graphics", "*.png")]

    if var == 0:
        filename = askopenfilename(title="Open File", filetypes=availableFormats)
    elif var == 1:
        filename = asksaveasfilename(title="Save File", filetypes=availableFormats)
    elif var == 2:
        filename = asksaveasfilename(title="Export File", filetypes=availableFormats)

    if filename:
        name = filename[:]
        return name 
开发者ID:Burakcoli,项目名称:Pyint_Pixel-Painter,代码行数:21,代码来源:pyint.py

示例14: __init__

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import asksaveasfilename [as 别名]
def __init__(self,
                 *args,
                 filetypes=[],
                 defaultextension="",
                 action,
                 **kwargs):

        super().__init__(*args, **kwargs)
        self.defaultextension = defaultextension
        self.filetypes = filetypes

        if action == 'save':
            self.ask_func = filedialog.asksaveasfilename
        elif action == 'open':
            self.ask_func = filedialog.askopenfilename
        else:
            raise TypeError("Unknown action type: {}".format(action)) 
开发者ID:eigengrau,项目名称:tts-backup,代码行数:19,代码来源:entry.py

示例15: new_db

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog 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


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