Python tkFileDialog 模块,askopenfile() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用tkFileDialog.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)
项目: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)
项目:SandmanChess    作者:ThomasMadappattu    | 项目源码 | 文件源码
def handle_open_pgn(self):
                self.pgn_file = tkFileDialog.askopenfile(mode='r')
                if ( self.pgn_file is None ):
                    return 
                self.header_list = list()
                self.offset_list = list()
                self.pgn_item_list = list()
                print(self.pgn_file)
                for offset,headers in chess.pgn.scan_headers(self.pgn_file):
                        header_string = ""
                        for key in headers.keys():
                            header_string +=str(headers[key]) + "  "
                        header_string +="\n"
                        self.header_list.append(header_string)
                        print(headers.keys)
                        self.offset_list.append(offset)
                        self.pgn_item_list.append(PgnItem(header_string,offset))
                self.pgnDialog = PgnDialog(self,self.pgn_item_list)
项目:sendobox    作者:sendobox    | 项目源码 | 文件源码
def load_config():
    config_file = tkFileDialog.askopenfile("r")
    # Get parameters from .txt file
    [username, password, start_date, end_date, area_of_interest, platform, max_cloud_cover, download_path, image_id, download_options,
     image_path, preprocessing_options] = configuration.read_txt(config_file)
    # Clear old values
    clear_all()
    # Set new settings
    entries.set(username, password, start_date, end_date, area_of_interest, platform, max_cloud_cover, download_path, download_options,
                image_id, image_path, preprocessing_options, textbox_username, textbox_password, textbox_start_date,
                textbox_end_date, textbox_aoi, variable_sentinel1, variable_sentinel2, textbox_cloud_cover, textbox_download_path,
                textbox_product_id, variable_save_metadata, variable_plot_footprints, variable_download_test_image,
                variable_download_all, textbox_image_path, variable_mosaick, variable_subset)

# Method for saving a configuration file
项目:G71    作者:nkp216    | 项目源码 | 文件源码
def Get_Load_File(self):
        myFormats = [('AutoCAD / QCAD Drawing','*.dxf'),\
        ('All File','*.*') ]
        inidir=self.config.load_path
        filename = askopenfile(initialdir=inidir,\
                               filetypes=myFormats)
        if not filename:
            return
        else:
            self.load_filename=filename.name

        self.Load_File(self.load_filename)
项目:G71    作者:nkp216    | 项目源码 | 文件源码
def Get_Load_File(self):
        myFormats = [('AutoCAD / QCAD Drawing','*.dxf'),\
        ('All File','*.*') ]
        inidir=self.config.load_path
        filename = askopenfile(initialdir=inidir,\
                               filetypes=myFormats)
        if not filename:
            return
        else:
            self.load_filename=filename.name

        self.Load_File(self.load_filename)
项目:kumodocs    作者:kumofx    | 项目源码 | 文件源码
def choose_file_dialog(**options):
    """ Creates an open file dialog to choose a file, and returns a handle to that file """
    root = Tk.Tk()
    root.geometry('0x0+400+400')
    root.wait_visibility()
    root.wm_attributes('-alpha', 0.0)
    root.lift()
    root.focus_force()
    chosen_files = tkFileDialog.askopenfile(**options)
    root.destroy()
    return chosen_files
项目:AstroCrypt    作者:Faizaankhan3    | 项目源码 | 文件源码
def load_file():
    global password, filename
    text_file = tkFileDialog.askopenfile()
    if text_file.name != None:
        filename = text_file.name
        var.set(filename)
项目:pyneje    作者:mrehqe    | 项目源码 | 文件源码
def open_image():
    im = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
    input = open('im','r')
    label_image.config = Label(image_tab, image=input)
    #print(im)
    #im = Image.open(name_image)
项目:SandmanChess    作者:ThomasMadappattu    | 项目源码 | 文件源码
def set_external_engine(self):
            engine_file=tkFileDialog.askopenfile(mode='r')
            if ( engine_file is None):
                return 
            self.enginePath = engine_file.name
            try:
                    self.set_engine_player()
            except:
                    tkMessageBox.showerror("Error", "Could not intialize!")
            self.decide_who_plays()
项目:DualFisheye    作者:ooterness    | 项目源码 | 文件源码
def load_config(self, filename=None):
        if filename is None:
            file_obj = tkFileDialog.askopenfile()
            if file_obj is None: return
        else:
            file_obj = open(filename, 'r')
        try:
            load_config(file_obj, self.lens1, self.lens2)
        except:
            tkMessageBox.showerror('Config load error', traceback.format_exc())
项目:DualFisheye    作者:ooterness    | 项目源码 | 文件源码
def _file_select(self, tkstr):
        result = tkFileDialog.askopenfile()
        if result is not None:
            tkstr.set(result.name)
            result.close()

    # Make a combined label/textbox/slider for a given variable: