Python tkinter.filedialog 模块,askopenfile() 实例源码

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

项目:SceneDensity    作者:ImOmid    | 项目源码 | 文件源码
def openBox(
            self,
            title=None,
            dirName=None,
            fileTypes=None,
            asFile=False):

        self.topLevel.update_idletasks()

        # define options for opening
        options = {}

        if title is not None:
            options['title'] = title
        if dirName is not None:
            options['initialdir'] = dirName
        if fileTypes is not None:
            options['filetypes'] = fileTypes

        if asFile:
            return filedialog.askopenfile(mode="r", **options)
        # will return "" if cancelled
        else:
            return filedialog.askopenfilename(**options)
项目:Cryptokey_Generator    作者:8BitCookie    | 项目源码 | 文件源码
def openBox(
            self,
            title=None,
            dirName=None,
            fileTypes=None,
            asFile=False):

        self.topLevel.update_idletasks()

        # define options for opening
        options = {}

        if title is not None:
            options['title'] = title
        if dirName is not None:
            options['initialdir'] = dirName
        if fileTypes is not None:
            options['filetypes'] = fileTypes

        if asFile:
            return filedialog.askopenfile(mode="r", **options)
        # will return "" if cancelled
        else:
            return filedialog.askopenfilename(**options)
项目:Quiver    作者:DeflatedPickle    | 项目源码 | 文件源码
def install_zip(self):
        pack = filedialog.askopenfile("r")
        found_pack = False

        if pack:
            with zipfile.ZipFile(pack.name, "r") as z:
                for file in z.namelist():
                    if file == "pack.mcmeta":
                        # messagebox.showinfo("Information", "Found 'pack.mcmeta'.")
                        found_pack = True

                pack.close()

            if found_pack:
                try:
                    shutil.move(pack.name, self.resourcepack_location)
                except shutil.Error:
                    messagebox.showerror("Error", "This pack is already installed.")

            else:
                messagebox.showerror("Error", "Could not find 'pack.mcmeta'.")
项目:rollingshutterpy    作者:alexd3rsan    | 项目源码 | 文件源码
def select_input(self) -> None:
        file = askopenfile(title='Please select one (any) frame from your set of images.',
                           filetypes=[('Image Files', ['.jpeg', '.jpg', '.png', '.gif',
                                                       '.tiff', '.tif', '.bmp'])])
        if not file:
            return None

        dir_ = os.path.dirname(file.name)
        filetype = os.path.splitext(file.name)

        self.files = [os.path.abspath(os.path.join(dir_, f))
                      for f in os.listdir(dir_)
                       if f.endswith(filetype)]
        self.files.sort()

        self.btn_output['state'] = 'normal'
项目:BeachedWhale    作者:southpaw5271    | 项目源码 | 文件源码
def openBox(
            self,
            title=None,
            dirName=None,
            fileTypes=None,
            asFile=False):

        self.topLevel.update_idletasks()

        # define options for opening
        options = {}

        if title is not None:
            options['title'] = title
        if dirName is not None:
            options['initialdir'] = dirName
        if fileTypes is not None:
            options['filetypes'] = fileTypes

        if asFile:
            return filedialog.askopenfile(mode="r", **options)
        # will return "" if cancelled
        else:
            return filedialog.askopenfilename(**options)
项目:Quiver    作者:DeflatedPickle    | 项目源码 | 文件源码
def open_zip(self):
        pack = filedialog.askopenfile("r", initialdir=self.resourcepack_location)
        found_pack = False

        if pack:
            amount = functions.zip_files(pack.name)
            progress = dialog.ProgressWindow(self.parent, title="Opening Zip", maximum=amount)

            count = 0

            with zipfile.ZipFile(pack.name, "r") as z:
                for file in z.namelist():
                    if file == "pack.mcmeta":
                        # messagebox.showinfo("Information", "Found 'pack.mcmeta'.")
                        found_pack = True
                        self.destroy()

                if found_pack:
                    self.parent.d = tempfile.TemporaryDirectory()
                    for file in z.namelist():
                        z.extract(file, self.parent.d.name)

                        count += 1
                        progress.variable_name.set("Current File: " + file)
                        progress.variable_percent.set("{}% Complete".format(round(100 * float(count) / float(amount))))
                        progress.variable_progress.set(progress.variable_progress.get() + 1)

                    self.parent.name = pack.name.split("/")[-1].split(".")[0]
                    self.parent.directory = self.parent.d.name
                    self.parent.directory_real = pack.name
                    self.parent.cmd.tree_refresh()
                    self.destroy()

                elif not found_pack:
                    messagebox.showerror("Error", "Could not find 'pack.mcmeta'.")

                pack.close()
            progress.destroy()
项目:Quiver    作者:DeflatedPickle    | 项目源码 | 文件源码
def install_server_pack(self):
        pack = filedialog.askopenfile(initialdir=self.resourcepack_location_server)
        pack.close()
        os.rename(pack.name, pack.name + ".zip")
        shutil.move(pack.name + ".zip", self.resourcepack_location)
项目:Quiver    作者:DeflatedPickle    | 项目源码 | 文件源码
def replace_file(self):
        old_file = self.widget_tree.item(self.widget_tree.focus())["tags"][0]
        file = filedialog.askopenfile()

        if file:
            new_file = file.name

            # os.replace(new_file, old_file)
            shutil.copy2(new_file, old_file)
            self.cmd.tree_refresh()
项目:pkinter    作者:DeflatedPickle    | 项目源码 | 文件源码
def _browse(self):
        """Opens a file browser."""
        file = filedialog.askopenfile(filetype=self._filetypes, initialdir=self._directory)
        self._variable.set(file.name)
        file.close()
项目:PigeonScript    作者:SilversApprentice    | 项目源码 | 文件源码
def open_file(self):
        opennm = tkfd.askopenfile()
        if not opennm == None:
            f = Path(opennm.name).read_text()
            self.has_saved = True
            self.saved_path = opennm.name
            return f
        else:
            return ""
项目:Ele-Text-Editor    作者:Thirsty-Robot    | 项目源码 | 文件源码
def openFileHK(self):
    f = filedialog.askopenfile(mode='r')
    t = f.read()
    text.delete(0.0, END)
    text.insert(0.0, t)

#Loops commands
项目:Ele-Text-Editor    作者:Thirsty-Robot    | 项目源码 | 文件源码
def openFile():
    f = filedialog.askopenfile(mode='r')
    t = f.read()
    text.delete(0.0, END)
    text.insert(0.0, t)
######################################################################

#Main GUI
项目:Zipy    作者:DeflatedPickle    | 项目源码 | 文件源码
def open_file(program):
    file = filedialog.askopenfile()
    if file is None:
        return
    program.open_file(file.name)
    file.close()
项目:MovieRecommend    作者:MrHohn    | 项目源码 | 文件源码
def load_history(self):
        f = filedialog.askopenfile(mode='r', filetypes=[self.get_filetype()], defaultextension=self.get_filetype()[1])
        if f is None:
            return
        self.historyList[self.searchMode].clear()
        for line in f:
            self.historyList[self.searchMode].add(line)
        self.historyVar.set(tuple(self.historyList[self.searchMode]))
        f.close()
项目:synthesizer    作者:irmen    | 项目源码 | 文件源码
def load_preset(self):
        file = askopenfile(filetypes=[("Synth presets", "*.ini")])
        cf = ConfigParser()
        cf.read_file(file)
        file.close()
        # general settings
        self.samplerate_choice.set(cf["settings"]["samplerate"])
        self.rendering_choice.set(cf["settings"]["rendering"])
        self.a4_choice.set(cf["settings"]["a4tuning"])
        self.to_speaker_lb.selection_clear(0, tk.END)
        to_speaker = cf["settings"]["to_speaker"]
        to_speaker = tuple(to_speaker.split(','))
        for o in to_speaker:
            self.to_speaker_lb.selection_set(int(o)-1)
        for section in cf.sections():
            if section.startswith("oscillator"):
                num = int(section.split('_')[1])-1
                osc = self.oscillators[num]
                for name, value in cf[section].items():
                    getattr(osc, name).set(value)
                osc.waveform_selected()
            elif section.startswith("envelope"):
                num = int(section.split('_')[1])-1
                env = self.envelope_filters[num]
                for name, value in cf[section].items():
                    getattr(env, name).set(value)
            elif section == "arpeggio":
                for name, value in cf[section].items():
                    getattr(self.arp_filter, name).set(value)
            elif section == "tremolo":
                for name, value in cf[section].items():
                    getattr(self.tremolo_filter, name).set(value)
            elif section == "echo":
                for name, value in cf[section].items():
                    getattr(self.echo_filter, name).set(value)
        self.statusbar["text"] = "preset loaded."