Python tkinter.filedialog.askopenfilename() Examples

The following are 30 code examples of tkinter.filedialog.askopenfilename(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tkinter.filedialog , or try the search function .
Example #1
Source Project: paper.io.sessdsa   Author: chbpku   File: 5.visualize.py    License: GNU General Public License v3.0 8 votes vote down vote up
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))

    # 定义合法输入类 
Example #2
Source Project: paper.io.sessdsa   Author: chbpku   File: 5.visualize.py    License: GNU General Public License v3.0 7 votes vote down vote up
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))

    # 保存记录 
Example #3
Source Project: Tkinter-GUI-Programming-by-Example   Author: PacktPublishing   File: avatarwindow.py    License: MIT License 6 votes vote down vote up
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) 
Example #4
Source Project: Andromeda   Author: liucaide   File: ui_input.py    License: MIT License 6 votes vote down vote up
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) 
Example #5
Source Project: razzy-spinner   Author: rafasashi   File: chartparser_app.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #6
Source Project: razzy-spinner   Author: rafasashi   File: chartparser_app.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #7
Source Project: paper.io.sessdsa   Author: chbpku   File: 6.glory_of_mankind.py    License: GNU General Public License v3.0 6 votes vote down vote up
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))

    # 定义合法输入类 
Example #8
Source Project: paper.io.sessdsa   Author: chbpku   File: visualize.py    License: GNU General Public License v3.0 6 votes vote down vote up
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))

    # 定义合法输入类 
Example #9
Source Project: paper.io.sessdsa   Author: chbpku   File: visualize.py    License: GNU General Public License v3.0 6 votes vote down vote up
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))

    # 保存记录 
Example #10
Source Project: ms_deisotope   Author: mobiusklein   File: view.py    License: Apache License 2.0 6 votes vote down vote up
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() 
Example #11
Source Project: vy   Author: vyapp   File: tabs.py    License: MIT License 6 votes vote down vote up
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' 
Example #12
Source Project: vy   Author: vyapp   File: io.py    License: MIT License 6 votes vote down vote up
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.') 
Example #13
Source Project: python-dvr   Author: NeiroNx   File: DeviceManager.py    License: MIT License 6 votes vote down vote up
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"]]) 
Example #14
Source Project: AI_Sudoku   Author: neeru1207   File: MainUI.py    License: Creative Commons Zero v1.0 Universal 6 votes vote down vote up
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") 
Example #15
Source Project: talking-head-anime-demo   Author: pkhungurn   File: manual_poser.py    License: MIT License 6 votes vote down vote up
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 
Example #16
Source Project: Tkinter-GUI-Application-Development-Blueprints-Second-Edition   Author: PacktPublishing   File: 3.12.py    License: MIT License 6 votes vote down vote up
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") 
Example #17
Source Project: Tkinter-GUI-Application-Development-Blueprints-Second-Edition   Author: PacktPublishing   File: 3.09.py    License: MIT License 6 votes vote down vote up
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") 
Example #18
Source Project: Tkinter-GUI-Programming-by-Example   Author: PacktPublishing   File: texteditor.py    License: MIT License 5 votes vote down vote up
def load_syntax_highlighting_file(self):
        syntax_file = filedialog.askopenfilename(filetypes=[("YAML file", ("*.yaml", "*.yml"))])
        if syntax_file:
            self.highlighter.clear_highlight()
            self.highlighter = Highlighter(self.text_area, syntax_file)
            self.highlighter.force_highlight() 
Example #19
Source Project: Tkinter-GUI-Programming-by-Example   Author: PacktPublishing   File: texteditor.py    License: MIT License 5 votes vote down vote up
def file_open(self, event=None):
        """
        Ctrl+O
        """
        file_to_open = filedialog.askopenfilename()
        if file_to_open:
            self.open_file = file_to_open

            self.text_area.display_file_contents(file_to_open)
            self.highlighter.force_highlight()
            self.line_numbers.force_update() 
Example #20
Source Project: Tkinter-GUI-Programming-by-Example   Author: PacktPublishing   File: texteditor.py    License: MIT License 5 votes vote down vote up
def load_syntax_highlighting_file(self):
        syntax_file = filedialog.askopenfilename(filetypes=[("YAML file", ("*.yaml", "*.yml"))])
        if syntax_file:
            self.highlighter.clear_highlight()
            self.highlighter = Highlighter(self.text_area, syntax_file)
            self.highlighter.force_highlight() 
Example #21
Source Project: Tkinter-GUI-Programming-by-Example   Author: PacktPublishing   File: texteditor.py    License: MIT License 5 votes vote down vote up
def file_open(self, event=None):
        """
        Ctrl+O
        """
        file_to_open = filedialog.askopenfilename()
        if file_to_open:
            self.open_file = file_to_open

            self.text_area.display_file_contents(file_to_open)
            self.highlighter.force_highlight()
            self.line_numbers.force_update() 
Example #22
Source Project: Andromeda   Author: liucaide   File: ui_launch.py    License: MIT License 5 votes vote down vote up
def __click_select(self, entry, tag):
        if tag == 1:
            path = filedialog.askopenfilename()
            if len(path) > 0:
                self.plist_path.set(path)
        else:
            pass 
Example #23
Source Project: Andromeda   Author: liucaide   File: ui_input.py    License: MIT License 5 votes vote down vote up
def __select_excel_input(self, entry_box):
        path = filedialog.askopenfilename()
        entry_box.delete(0, len(entry_box.get()))
        entry_box.insert(0, path)
        self.project_path = path

    # 如果 函数内部没有使用到 self. 会提示 Method 'select_excel_input' may be 'static' less... (⌘F1)
    # 会建议你 要么 加上@staticmethod ,要么放到class外面去 
Example #24
Source Project: razzy-spinner   Author: rafasashi   File: chartparser_app.py    License: GNU General Public License v3.0 5 votes vote down vote up
def load_chart_dialog(self, *args):
        filename = askopenfilename(filetypes=self.CHART_FILE_TYPES,
                                   defaultextension='.pickle')
        if not filename: return
        try: self.load_chart(filename)
        except Exception as e:
            tkinter.messagebox.showerror('Error Loading Chart',
                                   'Unable to open file: %r\n%s' %
                                   (filename, e)) 
Example #25
Source Project: Jtyoui   Author: jtyoui   File: tk.py    License: MIT License 5 votes vote down vote up
def select_pdf():
    global FILE
    FILE = filedialog.askopenfilename(filetypes=(("PDF file", "*.pdf"),))  # 获得pdf文件地址 
Example #26
Source Project: rpg-text   Author: Dogeek   File: map-creator.py    License: MIT License 5 votes vote down vote up
def _on_data_load(self, *args):
        fname = fd.askopenfilename()
        if not os.path.exists(fname):
            return
        self.data.load(fname)
        for v in [_ for _ in self.data.data.values() if _]:
            x, y = v['position']
            x *= 16
            y *= 16
            self.canvas.create_rectangle(x, y, x + 16, y + 16, stipple='gray50', fill='grey') 
Example #27
Source Project: RAASNet   Author: leonv024   File: RAASNet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def select_icon(self):
        self.options['icon_path'].set(askopenfilename(initialdir = "./", title = 'Select Icon...', filetypes = (('Icon Files', '*.ico'), ('All Files', '*.*')))) 
Example #28
Source Project: RAASNet   Author: leonv024   File: RAASNet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def select_payload(self):
        self.options['payload_path'].set(askopenfilename(initialdir = "./", title = 'Select Payload...', filetypes = (('Python Files', '*.py'), ('All Files', '*.*')))) 
Example #29
Source Project: RAASNet   Author: leonv024   File: RAASNet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def select_decryptor(self):
        self.options['decryptor_path'].set(askopenfilename(initialdir = "./", title = 'Select Decryptor...', filetypes = (('Python Files', '*.py'), ('All Files', '*.*')))) 
Example #30
Source Project: RAASNet   Author: leonv024   File: RAASNet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def set_img(self):
        try:
            f = base64.b64encode(open(askopenfilename(initialdir = "./", title = 'Select Image...', filetypes = ([('Image Files', '*.png *.jpg')])), 'rb').read()).decode('utf-8')
        except FileNotFoundError:
            return

        self.options['img_base64'].set(f)