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


Python filedialog.askopenfilename方法代码示例

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


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

示例1: load_chart

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_chart(self, *args):
        "Load a chart from a pickle file"
        filename = askopenfilename(filetypes=self.CHART_FILE_TYPES,
                                   defaultextension='.pickle')
        if not filename: return
        try:
            with open(filename, 'rb') as infile:
                chart = pickle.load(infile)
            self._chart = chart
            self._cv.update(chart)
            if self._matrix: self._matrix.set_chart(chart)
            if self._matrix: self._matrix.deselect_cell()
            if self._results: self._results.set_chart(chart)
            self._cp.set_chart(chart)
        except Exception as e:
            raise
            tkinter.messagebox.showerror('Error Loading Chart',
                                   'Unable to open file: %r' % filename) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:20,代码来源:chartparser_app.py

示例2: choose_image

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def choose_image(self):
        image_file = filedialog.askopenfilename(filetypes=self.image_file_types)

        if image_file:
            avatar = Image.open(image_file)
            avatar.thumbnail((128, 128))
            avatar.save(avatar_file_path, "PNG")

            img_contents = ""
            img_b64 = ""
            with open(avatar_file_path, "rb") as img:
                img_contents = img.read()
                img_b64 = base64.urlsafe_b64encode(img_contents)

            self.master.requester.update_avatar(self.master.username, img_b64)

            self.current_avatar_image = tk.PhotoImage(file=avatar_file_path)
            self.current_avatar.configure(image=self.current_avatar_image) 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:20,代码来源:avatarwindow.py

示例3: load_tab

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_tab():
    """
    It pops a askopenfilename window to drop
    the contents of a file into another tab's text area.
    """

    filename = askopenfilename()

    # If i don't check it ends up cleaning up
    # the text area when one presses cancel.

    if not filename: 
        return 'break'

    try:
        root.note.load([ [filename] ])
    except Exception:
        root.status.set_msg('It failed to load.')
    else:
        root.status.set_msg('File loaded.')
    return 'break' 
开发者ID:vyapp,项目名称:vy,代码行数:23,代码来源:tabs.py

示例4: __click_select

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def __click_select(self, entry, tag):

        if tag == 1:
            path = filedialog.askopenfilename()
            if len(path) > 0:
                t = '/'
                list = path.split('/')
                pro = list.pop()
                path = t.join(list)
                self.is_workspace.set('.xcworkspace' in pro)
                tag = pro.split('.')[0]
                self.project_path.set(path)
                self.target.set(tag)
        else:
            path = filedialog.askopenfilename()
            if len(path) > 0:
                t = '/'
                self.plist_path.set(path)
                list = path.split('/')
                pro = list.pop()
                self.is_release.set('AppStore' in pro) 
开发者ID:liucaide,项目名称:Andromeda,代码行数:23,代码来源:ui_input.py

示例5: load_grammar

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_grammar(self, *args):
        "Load a grammar from a pickle file"
        filename = askopenfilename(filetypes=self.GRAMMAR_FILE_TYPES,
                                   defaultextension='.cfg')
        if not filename: return
        try:
            if filename.endswith('.pickle'):
                with open(filename, 'rb') as infile:
                    grammar = pickle.load(infile)
            else:
                with open(filename, 'r') as infile:
                    grammar = CFG.fromstring(infile.read())
            self.set_grammar(grammar)
        except Exception as e:
            tkinter.messagebox.showerror('Error Loading Grammar',
                                   'Unable to open file: %r' % filename) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:18,代码来源:chartparser_app.py

示例6: browse_directory

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def browse_directory(self, option):
        if option == "pcap":
            # Reference: http://effbot.org/tkinterbook/tkinter-dialog-windows.htm
            self.pcap_file.set(fd.askopenfilename(initialdir = sys.path[0],title = "Select Packet Capture File!",filetypes = (("All","*.pcap *.pcapng"),("pcap files","*.pcap"),("pcapng files","*.pcapng"))))
            self.filename = self.pcap_file.get().replace(".pcap","")
            if "/" in self.filename:
                self.filename = self.filename.split("/")[-1]
            #,("all files","*.*")
            #self.filename_field.delete(0, END)
            #self.filename_field.insert(0, self.pcap_file)
            print(self.filename)
            print(self.pcap_file)
        else:
            self.destination_report.set(fd.askdirectory())
            if self.destination_report.get():
                if not os.access(self.destination_report.get(), os.W_OK):
                    mb.showerror("Error","Permission denied to create report! Run with higher privilege.")
            else:
                mb.showerror("Error", "Enter a output directory!") 
开发者ID:Srinivas11789,项目名称:PcapXray,代码行数:21,代码来源:user_interface.py

示例7: load_ai

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_ai(self):
            path = askopenfilename(filetypes=[('AI脚本', '*.py')])
            if not path:
                return
            name, ext = os.path.splitext(os.path.basename(path))

            try:
                if ext != '.py':
                    raise TypeError('不支持类型:%s' % ext)

                class load:
                    with open(path, encoding='utf-8', errors='ignore') as f:
                        exec(f.read())

                load.play
                self.AI_MODULE = load
                self.AI_NAME = name
                self.AI_info.set(name)
                clear_storage()
            except Exception as e:
                showerror('%s: %s' % (self.name, type(e).__name__), str(e))

    # 定义合法输入类 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:25,代码来源:5.visualize.py

示例8: load_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_log():
        log_path = askopenfilename(filetypes=[('对战记录文件', '*.zlog'), ('全部文件',
                                                                     '*.*')])
        if not log_path: return
        try:
            with open(log_path, 'rb') as file:
                log = pickle.loads(zlib.decompress(file.read()))
            global MATCH_LOG
            MATCH_LOG = log
            tk.title('Log: %s' % os.path.basename(log_path))
            display.load_match_result(log)
        except Exception as e:
            showerror('%s: %s' % (os.path.split(log_path)[1],
                                  type(e).__name__), str(e))

    # 保存记录 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:18,代码来源:5.visualize.py

示例9: load_log

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_log():
        log_path = askopenfilename(filetypes=[('对战记录文件', '*.clog;*.zlog'), ('全部文件',
                                                                     '*.*')])
        if not log_path: return
        try:
            if log_path.endswith('.zlog'):
                log = match_interface.load_match_log(log_path)
            elif log_path.endswith('.clog'):
                log = match_interface.load_compact_log(log_path)
            else:
                raise ValueError('后缀名非法')
            global MATCH_LOG
            MATCH_LOG = log
            tk.title('Log: %s' % os.path.basename(log_path))
            display.load_match_result(log)
        except Exception as e:
            raise
            showerror('%s: %s' % (os.path.split(log_path)[1],
                                  type(e).__name__), str(e))

    # 保存记录 
开发者ID:chbpku,项目名称:paper.io.sessdsa,代码行数:23,代码来源:visualize.py

示例10: main

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def main():
    base = Tk()
    base.title("ms_deisotope Spectrum Viewer")
    tk.Grid.rowconfigure(base, 0, weight=1)
    tk.Grid.columnconfigure(base, 0, weight=1)
    app = SpectrumViewer(base)
    app.do_layout()

    try:
        fname = sys.argv[1]
    except IndexError:
        fname = None
        # fname = tkfiledialog.askopenfilename()
    print("initial value", fname)
    app.ms_file_name = fname

    app.mainloop() 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:19,代码来源:view.py

示例11: ask_and_load

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def ask_and_load(self, event):
        """
        It pops a askopenfilename to find a file to drop
        the contents in the focused text area.
        """
    
        filename = askopenfilename()
    
        # If i don't check it ends up cleaning up
        # the text area when one presses cancel.
    
        if not filename: 
            return
    
        try:
            self.area.load_data(filename)
        except Exception:
            root.status.set_msg('It failed to load.')
        else:
            root.status.set_msg('File loaded.') 
开发者ID:vyapp,项目名称:vy,代码行数:22,代码来源:io.py

示例12: flash

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def flash(self):
        self.fl_state.set("Processing...")
        filename = askopenfilename(
            filetypes=((_("Flash"), "*.bin"), (_("All files"), "*.*"))
        )
        if filename == "":
            return
        if len(self.table.selection()) == 0:
            _mac = "all"
        else:
            _mac = self.table.item(self.table.selection()[0], option="values")[4]
        result = ProcessCMD(
            ["flash", _mac, self.passw.get(), filename, self.fl_state.set]
        )
        if (
            hasattr(result, "keys")
            and "Ret" in result.keys()
            and result["Ret"] in CODES.keys()
        ):
            showerror(_("Error"), CODES[result["Ret"]]) 
开发者ID:NeiroNx,项目名称:python-dvr,代码行数:22,代码来源:DeviceManager.py

示例13: open_img

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def open_img(self):
        try:
            filename = filedialog.askopenfilename(title='open')
        except:
            return
        try:
            img = Image.open(filename)
        except:
            messagebox.showerror("ERROR", "Non Image File selected")
            return
        self.selectedimagepath = filename
        self.imagepathdisplay.configure(fg="black")
        self.imagepathdisplay.delete(0, END)
        self.imagepathdisplay.insert(0, filename)
        img = img.resize((490, 450), Image.ANTIALIAS)
        img = ImageTk.PhotoImage(img)
        self.imgpanel.configure(image=img)
        self.img = img
        self.nextbut.configure(fg="black") 
开发者ID:neeru1207,项目名称:AI_Sudoku,代码行数:21,代码来源:MainUI.py

示例14: load_image

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_image(self):
        file_name = filedialog.askopenfilename(
            filetypes=[("PNG", '*.png')],
            initialdir="data/illust")
        if len(file_name) > 0:
            image = PhotoImage(file=file_name)
            if image.width() != self.poser.image_size() or image.height() != self.poser.image_size():
                message = "The loaded image has size %dx%d, but we require %dx%d." \
                          % (image.width(), image.height(), self.poser.image_size(), self.poser.image_size())
                messagebox.showerror("Wrong image size!", message)
            self.source_image_label.configure(image=image, text="")
            self.source_image_label.image = image
            self.source_image_label.pack()

            self.source_image = extract_pytorch_image_from_filelike(file_name).to(self.torch_device).unsqueeze(dim=0)
            self.needs_update = True 
开发者ID:pkhungurn,项目名称:talking-head-anime-demo,代码行数:18,代码来源:manual_poser.py

示例15: load_project

# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfilename [as 别名]
def load_project(self):
        file_path = filedialog.askopenfilename(
            filetypes=[('Explosion Beat File', '*.ebt')], title='Load Project')
        if not file_path:
            return
        pickled_file_object = open(file_path, "rb")
        try:
            self.all_patterns = pickle.load(pickled_file_object)
        except EOFError:
            messagebox.showerror("Error",
                                 "Explosion Beat file seems corrupted or invalid !")
        pickled_file_object.close()
        try:
            self.change_pattern()
            self.root.title(os.path.basename(file_path) + PROGRAM_NAME)
        except:
            messagebox.showerror("Error",
                                 "An unexpected error occurred trying to process the beat file") 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代码行数:20,代码来源:3.12.py


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