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

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

项目:NYCSL2    作者:HMProgrammingClub    | 项目源码 | 文件源码
def loadPiecesFile():
    global movesString
    global piecesString
    global status

    filename = filedialog.askopenfilename()
    if not filename.endswith('.txt'):
        messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
    else:
        with open(filename, 'r') as infile:
            piecesString = infile.read().replace('\n', '')
        if piecesString is not None and movesString is not None:
            status.set("Pieces: Loaded\nMoves: Loaded")
            generateFrames(piecesString,movesString)
        elif movesString is None:
            status.set("Pieces: Loaded\nMoves: Not Loaded")
项目: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)
项目:NYCSL2    作者:HMProgrammingClub    | 项目源码 | 文件源码
def loadMovesFile():
    global movesString
    global piecesString
    global status

    filename = filedialog.askopenfilename()
    if not filename.endswith('.txt'):
        messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
    else:
        with open(filename, 'r') as infile:
            movesString = infile.read().replace('\n', '')
        if piecesString is not None and movesString is not None:
            status.set("Pieces: Loaded\nMoves: Loaded")
            generateFrames(piecesString,movesString)
        elif piecesString is None:
            status.set("Pieces: Not Loaded\nMoves: Loaded")
项目:NYCSL2    作者:HMProgrammingClub    | 项目源码 | 文件源码
def loadMovesFile():
    global movesString
    global piecesString
    global status

    filename = filedialog.askopenfilename()
    if not filename.endswith('.txt'):
        messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
    else:
        with open(filename, 'r') as infile:
            movesString = infile.read().replace('\n', '')
        if piecesString is not None and movesString is not None:
            status.set("Pieces: Loaded\nMoves: Loaded")
            generateFrames(piecesString,movesString)
        elif piecesString is None:
            status.set("Pieces: Not Loaded\nMoves: Loaded")
项目:NYCSL2    作者:HMProgrammingClub    | 项目源码 | 文件源码
def loadPiecesFile():
    global movesString
    global piecesString
    global status

    filename = filedialog.askopenfilename()
    if not filename.endswith('.txt'):
        messagebox.showinfo("Visualizer error", "Filetype must be a .txt")
    else:
        with open(filename, 'r') as infile:
            piecesString = infile.read().replace('\n', '')
        if piecesString is not None and movesString is not None:
            status.set("Pieces: Loaded\nMoves: Loaded")
            generateFrames(piecesString,movesString)
        elif movesString is None:
            status.set("Pieces: Loaded\nMoves: Not Loaded")
项目: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)
项目:docximport-sigil-plugin    作者:dougmassay    | 项目源码 | 文件源码
def fileChooser(self, ftype, tkentry, tkcheck=None, tkbutton=None):
        file_opt = FTYPE_MAP[ftype]
        file_opt['parent'] = None
        file_opt['initialdir'] = self.prefs['lastDir'][ftype]
        file_opt['multiple'] = False
        inpath = askopenfilename(**file_opt)
        if len(inpath):
            tkentry.config(state="normal")
            tkentry.delete(0, tkinter.constants.END)
            tkentry.insert(0, os.path.normpath(inpath))
            self.prefs['lastDir'][ftype] = os.path.dirname(inpath)
            tkentry.config(state="readonly")
        else:
            if tkcheck is not None:
                tkcheck.deselect()
            if tkbutton is not None:
                tkbutton.config(state='disabled')
项目:knowledge-management    作者:dgore7    | 项目源码 | 文件源码
def apply_settings(self, gui, filename, category, keywords):
        # TODO: Change to use the above methods for setting the keyfiles.
        # TODO: Also needs to evenually allow for LE certs and self-signed.

        gui.keyFilename = filedialog.askopenfilename(initialdir="/", title="Select file")
        print(gui.filename)
        self.filenameInput.insert(0, gui.filename)
        response = gui.getClient().upload(filename, category, keywords)
        """
            Goes back to the home page.
        """
        gui.show_frame(home_gui.HomePage)

    # self.filenameInput.delete(0, 'end')
    # self.categoryInput.delete(0, 'end')
    # self.keywordsInput.delete(0, 'end')
项目:Tkinter-By-Example    作者:Dvlv    | 项目源码 | 文件源码
def file_open(self, event=None):
        file_to_open = filedialog.askopenfilename()

        if file_to_open:
            self.open_file = file_to_open
            self.main_text.delete(1.0, tk.END)

            with open(file_to_open, "r") as file_contents:
                file_lines = file_contents.readlines()
                if len(file_lines) > 0:
                    for index, line in enumerate(file_lines):
                        index = float(index) + 1.0
                        self.main_text.insert(index, line)

        self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))

        final_index = self.main_text.index(tk.END)
        final_line_number = int(final_index.split(".")[0])

        for line_number in range(final_line_number):
            line_to_tag = ".".join([str(line_number), "0"])
            self.tag_keywords(None, line_to_tag)
项目:Tkinter-By-Example    作者:Dvlv    | 项目源码 | 文件源码
def file_open(self, event=None):
        file_to_open = filedialog.askopenfilename()

        if file_to_open:
            self.open_file = file_to_open
            self.main_text.delete(1.0, tk.END)

            with open(file_to_open, "r") as file_contents:
                file_lines = file_contents.readlines()
                if len(file_lines) > 0:
                    for index, line in enumerate(file_lines):
                        index = float(index) + 1.0
                        self.main_text.insert(index, line)

        self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))

        self.tag_all_lines()
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
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)
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
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)
项目:of    作者:OptimalBPM    | 项目源码 | 文件源码
def on_load_json(self, *args):
        """Triggered when load-button is clicked.
        Displays a load dialog, clears the GUI, populates the merge and uppdates the GUI"""
        _setup_filename = filedialog.askopenfilename(defaultextension=".json",
                                               filetypes=[('JSON files', '.json'), ('all files', '.*')],
                                               title="Choose file")
        if _setup_filename is not None:
            self.notify_task('Loading setup..', 0)
            try:
                self.setup.load_from_file(_setup_filename=_setup_filename)
                self.setup_filename.set(_setup_filename)
            except Exception as e:
                self.notify_messagebox("Error loading data", str(e))
            self.setup_to_gui()

            self.notify_task('Loading setup..done', 100)
            self.resize()
项目:qal    作者:OptimalBPM    | 项目源码 | 文件源码
def select_file(self, _default_extension, _file_types):
        """Brings up a selector dialog, prompting the user to select a file,
        the relative path if the file is then saved to the filename property.
        Also, the base path is set.
        """
        if self.is_destination is True:
            _filename = filedialog.asksaveasfilename(initialdir=os.path.dirname(self.filename.get()),
                                               defaultextension=_default_extension,
                                               filetypes=_file_types,
                                               title="Choose destination file")
        else:
            _filename = filedialog.askopenfilename(initialdir=os.path.dirname(self.filename.get()),
                                               defaultextension=_default_extension,
                                               filetypes=_file_types,
                                               title="Choose source file")
        if _filename:
            self.base_path = os.path.dirname(_filename)
            self.filename.set(os.path.relpath(_filename, self.base_path))
项目:ted-editor    作者:tarnheld    | 项目源码 | 文件源码
def load_TED():
    '''Loads a TED file and returns a TrackObject'''
    root=tk.Tk()
    root.withdraw()
    root.attributes("-topmost", True)
    file_opt = options = {}
    options['defaultextension'] = '.ted'
    options['filetypes'] = [('GT6TED', '.ted')]
    options['initialdir'] = 'TED'
    options['parent'] = root
    options['title'] = 'Open file'

    path = filedialog.askopenfilename(**file_opt)
    filename = basename(path)
    root.destroy()
    try:
        with open(path, mode='rb') as file:
            tedfile = file.read()
            Track = initFromTedFile(tedfile, filename)

        return Track
    except FileNotFoundError:
        return None
项目: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)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
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)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
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)
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_updateFirmware():
    root.update()
    FWfileName=askopenfilename(filetypes=(("BennVenn Firmware File","*.BEN"),("All Files","*.*")))
    if FWfileName:
        FWfile=open(FWfileName,'rb')
        FWbuffer=FWfile.read()
        FWsize=len(FWbuffer)
        if FWsize==33280:
            dev.write(0x01,[0x03])
            USBbuffer = dev.read(0x81,64)
            app.lowerRightLabel.set(("File Size Correct"))
            for FWpos in range (512,33279,64):
                dev.write(0x01,FWbuffer[FWpos:FWpos+64])
        else:
            app.lowerRightLabel.set(("File Invalid"))
        FWfile.close()
        exit()
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write64kEEPROM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)

        for Address in range(0,1024):
            Lo2=Address&0xFF
            Me2=(Address&0xFF00) >> 8
            Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
            Me=Me2.to_bytes(1,'little')
            Lo=Lo2.to_bytes(1,'little')
            WriteCommand=b'\x37\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data8Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)

            for WriteDelay in range (0,10):#10 usb write transactions = 10ms
                dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])

        SRAMfile.close()
        print ('Done!')
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write4kEEPROM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)

        for Address in range(0,64):
            Lo2=Address&0xFF
            Me2=(Address&0xFF00) >> 8
            Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
            Me=Me2.to_bytes(1,'little')
            Lo=Lo2.to_bytes(1,'little')
            WriteCommand=b'\x3D\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data8Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)

            for WriteDelay in range (0,10):#10 usb write transactions = 10ms
                dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])

        SRAMfile.close()
        print ('Done!')
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write64kFLASHRAM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        main_GBA_FlashSaveErase()
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)
        dev.write(0x01,[0x39,0x00,0x00,0x00,0x00,0x00])
        RAMbuffer= dev.read(0x81,64)
        for Address in range(0,SRAMsize,32):
            Lo=Address&0xFF
            Me=(Address&0xFF00) >> 8
            Data32Bytes=SRAMbuffer[Address:Address+32]
            Me=Me.to_bytes(1,'little')
            Lo=Lo.to_bytes(1,'little')
            WriteCommand=b'\x3B\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data32Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)
        SRAMfile.close()
        print ('Done!')
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_updateFirmware():
    root.update()
    FWfileName=askopenfilename(filetypes=(("BennVenn Firmware File","*.BEN"),("All Files","*.*")))
    if FWfileName:
        FWfile=open(FWfileName,'rb')
        FWbuffer=FWfile.read()
        FWsize=len(FWbuffer)
        if FWsize==33280:
            dev.write(0x01,[0x03])
            USBbuffer = dev.read(0x81,64)
            app.lowerRightLabel.set(("File Size Correct"))
            for FWpos in range (512,33279,64):
                dev.write(0x01,FWbuffer[FWpos:FWpos+64])
        else:
            app.lowerRightLabel.set(("File Invalid"))
        FWfile.close()
        exit()
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write4kEEPROM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)

        for Address in range(0,64):
            Lo2=Address&0xFF
            Me2=(Address&0xFF00) >> 8
            Data8Bytes=SRAMbuffer[(Address*8):(Address*8)+8]
            Me=Me2.to_bytes(1,'little')
            Lo=Lo2.to_bytes(1,'little')
            WriteCommand=b'\x3D\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data8Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)

            for WriteDelay in range (0,10):#10 usb write transactions = 10ms
                dev.write(0x01,[0x38,0x00,0x00,Me2,Lo2])

        SRAMfile.close()
        print ('Done!')
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write64kSRAM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)

        for Address in range(0,SRAMsize,32):
            Lo=Address&0xFF
            Me=(Address&0xFF00) >> 8
            Data32Bytes=SRAMbuffer[Address:Address+32]
            Me=Me.to_bytes(1,'little')
            Lo=Lo.to_bytes(1,'little')
            WriteCommand=b'\x36\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data32Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)
        SRAMfile.close()
        print ('Done!')
项目:JoeyJoebags    作者:rebbTRSi    | 项目源码 | 文件源码
def main_GBA_Write64kFLASHRAM():
    root.update()
    SRAMfileName=askopenfilename(filetypes=(("GBA Save File","*.SAV"),("All Files","*.*")))
    if SRAMfileName:
        main_GBA_FlashSaveErase()
        SRAMfile=open(SRAMfileName,'rb')
        SRAMbuffer=SRAMfile.read()
        SRAMsize=len(SRAMbuffer)
        dev.write(0x01,[0x39,0x00,0x00,0x00,0x00,0x00])
        RAMbuffer= dev.read(0x81,64)
        for Address in range(0,SRAMsize,32):
            Lo=Address&0xFF
            Me=(Address&0xFF00) >> 8
            Data32Bytes=SRAMbuffer[Address:Address+32]
            Me=Me.to_bytes(1,'little')
            Lo=Lo.to_bytes(1,'little')
            WriteCommand=b'\x3B\x00\x00'+Me+Lo
            Dataout=WriteCommand+Data32Bytes
            dev.write(0x01,Dataout)
            RAMbuffer= dev.read(0x81,64)
        SRAMfile.close()
        print ('Done!')
项目:restclientgui    作者:profullstack    | 项目源码 | 文件源码
def open(self):
        filename = filedialog.askopenfilename(initialdir="data/")
        if filename:
            with open(filename, 'r') as f:
                o = json.load(f)
                self.methodvar.set(o["method"])
                self.schemavar.set(o["schema"])
                self.urlvar.set(o["url"])
                self.datah_text.delete(1.0,END)
                self.datah_text.insert(END,o["sheaders"])
                self.data_text.delete(1.0,END)
                self.data_text.insert(END,o["data"])
                self.response_headers.delete(1.0,END)
                self.response_headers.insert(END,o["response_headers"])
                self.response_data.delete(1.0,END)
                self.response_data.insert(END,o["response_data"])
项目:neighborhood_mood_aws    作者:jarrellmark    | 项目源码 | 文件源码
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)
项目:neighborhood_mood_aws    作者:jarrellmark    | 项目源码 | 文件源码
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)
项目:flight-stone    作者:asmateus    | 项目源码 | 文件源码
def browseFiles(self):
        self.filename = filedialog.askopenfilename(
            title='Select image source',
            filetypes=(('jpeg files', '*.jpg'), ('all files', '*.*'))
        )
        if self.filename:
            self.file_selection_string.set(self.filename.split('/')[-1])
            img = Image.open(self.filename)
            self.last_frame = np.array(img)
            self.img_update = True
            self.process_status[0] = 1

            self.manager.assignSourceImage(self.last_frame, self.filename)

            self.updateVideoHolder()
            self.updateInformation()
项目:hate-to-hugs    作者:sdoran35    | 项目源码 | 文件源码
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)
项目:hate-to-hugs    作者:sdoran35    | 项目源码 | 文件源码
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)
项目:warpWarp    作者:ahwmrklas    | 项目源码 | 文件源码
def loadGame(tkRoot):
    print("loadGame")
    #so we need to open a file select menu, filtering for .wwr
    #then we just parse the string to our dict.
    loadFileName = filedialog.askopenfilename(title = "Select file",filetypes = (("warpWar files","*.wwr"),("all files","*.*")))
    print (loadFileName)
    loadFile = open(loadFileName, 'r')
    gameString = loadFile.read()
    loadFile.close()
    gameDict = json.loads(gameString)

    #send the game to the server.
    sendJson = warpWarCmds().restoreGame(tkRoot.cfg.Profile.plid, gameDict)
    print (sendJson)
    tkRoot.hCon.sendCmd(sendJson)

# I don't like these. They don't seem very objecty
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
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)
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
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)
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
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)
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
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)
项目:kind2anki    作者:prz3m    | 项目源码 | 文件源码
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)
项目:kind2anki    作者:prz3m    | 项目源码 | 文件源码
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)
项目:but_sentiment    作者:MixedEmotions    | 项目源码 | 文件源码
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)
项目:but_sentiment    作者:MixedEmotions    | 项目源码 | 文件源码
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)
项目:qcri    作者:douville    | 项目源码 | 文件源码
def _load_run_results(self):
        filename = filedialog.askopenfilename()
        if not filename:
            return
        self.runresultsvar.set(filename)

        valid_parsers = importer.get_parsers(filename, self.cfg)
        if not valid_parsers:
            messagebox.showerror(
                'Unknown Format', 'Unable to parse this file. '
                'View log for details.')
            self.choose_parser['values'] = ['']
            self.choose_parser.current(0)
            self.choose_parser.event_generate('<<ComboboxSelected>>')
            return

        self.valid_parsers = {p.__name__: p for p in valid_parsers}
        self.choose_parser['values'] = list(self.valid_parsers.keys())
        if len(valid_parsers) > 1:
            self.choose_parser.config(state='enabled')
        self.choose_parser.current(0)
        self.choose_parser.event_generate('<<ComboboxSelected>>')
项目:PyFusionGUI    作者:SyntaxVoid    | 项目源码 | 文件源码
def restore_clustering(self):
        # A window pops up asking the user to specify the path of a *.ANobj (Analysis Object) file
        # and attempts to restore it using the Analysis.restore classmethod. Then opens a ClusteringWindow
        # which gives the user the option to plot clusters, save the object, or close the window.
        fname = askopenfilename(initialdir=IRIS_CSCRATCH_DIR,
                                filetypes=(("Analysis File Object", "*.ANobj"), ("All Files", "*.*")))
        if fname == "" or fname == (): return None
        try:
            self.AN = analysis.Analysis.restore(fname)
            self._restore_settings_from_loaded_object()
            self.root.event_generate("<<clustering_restored>>", when="tail")
            self.using_analysis_var.set("Using analysis object from\n{}".format(jt.break_path(fname, 24)))
            self.using_analysis_label.config(fg="dark green")
        except:
            ErrorWindow(self.root, "Incorrect file format.")
        return None
项目:dayworkspace    作者:copie    | 项目源码 | 文件源码
def upfile(self):

        url = "http://" + HOST + ":" + PORT + "/upfile"
        # ???????
        filename = filedialog.askopenfilename()
        self.lfc_field_1_t.delete('0.0', 'end')
        self.lfc_field_1_t.insert('0.0', "??????......")
        try:
            files = {'file': open(str(filename), 'rb')}
            req = requests.post(url, files=files)
            if req.status_code == 200:
                messagebox.showinfo("??", "????")
            else:
                messagebox.showinfo("??", "????????")
        except:
            messagebox.showinfo("??", "????????")
        finally:
            self.lfc_field_1_t.delete('0.0', 'end')

    # ????
项目:RunescapeBots    作者:lukegarbutt    | 项目源码 | 文件源码
def open_file(self):
        global once
        once = True
        img_file = filedialog.askopenfilename()
        # this makes sure you select a file
        # otherwise program crashes if not
        if img_file  != '':
            self.img_path = img_file 
            # this just makes sure the image shows up after opening it
            self.low_hue.set(self.low_hue.get()+1)
            self.low_hue.set(self.low_hue.get()-1)
        else:
            print('picked nothing')
            return 0
项目:sc8pr    作者:dmaccarthy    | 项目源码 | 文件源码
def __init__(self, response=str, text="", title=None, accept=0, **options):
        if response is bool:
            self.dialog = [askyesno, askokcancel, askretrycancel][accept]
        else: self.dialog = {None:showinfo, str:askstring, int:askinteger, float:askfloat,
            0:askopenfilename, 1:asksaveasfilename, 2:askdirectory}[response]
        self.options = options.copy()
        if "initialdir" in options:
            self.options["initialdir"] = abspath(options["initialdir"])
        if type(response) is int:
            self.args = tuple()
            if title: self.options["title"] = title
        else:
            if title is None:
                title = "Info" if response is None else "Confirm" if response is bool else "Input"
            self.args = title, text
项目:decaptcha    作者:Orzzet    | 项目源码 | 文件源码
def drawhistorigram(self, master):
        try:
            self.Lb1.delete(0, END)
        except:
            self.Lb1 = Listbox(master, selectmode=MULTIPLE)

        self.filename = askopenfilename()
        mostpixels = historigram(self.filename)
        for i in range(len(mostpixels)):
            self.Lb1.insert(i+1, "Pixels: " + str(mostpixels[i][1]) + ', ' + "Value: " +str(mostpixels[i][0]))
            self.Lb1.pack()
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
def open_file(self):
        filename = filedialog.askopenfilename()
        if filename and (
            not self.bodies or messagebox.askokcancel("Discard Changes", "Are you sure you want to discard changes?")):
            self.filename = filename
            self.name.set(os.path.split(filename)[-1])
            for window in self.properties_windows:
                window.destroy()
            self.properties_windows = []
            with open(filename) as file:
                self.bodies[:] = generate_bodies(load_save(self, file))
项目:desert-mirage    作者:valentour    | 项目源码 | 文件源码
def select_json():
    selection = filedialog.askopenfilename(initialdir=getcwd(),
                                           title='Select project json file')
    _jsonVar.set(selection)
    print('Selected json file: {}'.format(_jsonVar.get()))
项目:desert-mirage    作者:valentour    | 项目源码 | 文件源码
def select_seed():
    selection = filedialog.askopenfilename(initialdir=getcwd(),
                                           title='Select IVS seed file')
    _seedVar.set(selection)
    print('Selected seed file: {}'.format(_seedVar.get()))