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

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

项目:Cryptokey_Generator    作者:8BitCookie    | 项目源码 | 文件源码
def directoryBox(self, title=None, dirName=None):
        self.topLevel.update_idletasks()
        options = {}
        options['initialdir'] = dirName
        options['title'] = title
        options['mustexist'] = False
        fileName = filedialog.askdirectory(**options)
        if fileName == "":
            return None
        else:
            return fileName
项目:pymod    作者:pymodproject    | 项目源码 | 文件源码
def choose_path(self):
        """
        Called when users press the 'Browse' button in order to choose a path on their system.
        """
        current_path = self.getvalue()
        new_path = None

        # Lets users choose a new path.
        if self.path_type == "file":
            new_path = askopenfilename(title = self.askpath_title,
                initialdir=os.path.dirname(current_path),
                initialfile=os.path.basename(current_path), parent = get_parent_window(self), filetypes = self.file_types)

        elif self.path_type == "directory":
            new_path = askdirectory(title = self.askpath_title, initialdir=os.path.dirname(current_path), mustexist = True, parent = get_parent_window(self))

        # Updates the text in the Entry with the new path name.
        if new_path:
            self.clear()
            self.setvalue(new_path)

        if hasattr(self.run_after_selection, "__call__"):
            self.run_after_selection()
项目:HSL_Dev    作者:MaxJackson    | 项目源码 | 文件源码
def get_dirname():
    Tk().withdraw()
    print("Initializing Dialogue...\nPlease select a directory.")
    dirname = askdirectory(initialdir=os.getcwd(),title='Please select a directory')
    if len(dirname) > 0:
        print ("You chose %s" % dirname)
        return dirname
    else: 
        dirname = os.getcwd()
        print ("\nNo directory selected - initializing with %s \n" % os.getcwd())
        return dirname
项目:Circadia    作者:hooyah    | 项目源码 | 文件源码
def menu_saveThemeAs(self):
        """ callback for saveAs menu item """

        newTheme = tkFileDialog.askdirectory(mustexist=True, initialdir=self.themeRootPath, title='Open Theme')
        if newTheme and os.path.isdir(newTheme):
            if os.path.isfile(newTheme+os.path.sep+'theme.json'):
                if not tkMessageBox.askyesno(title='Save theme', message='Theme exists. Overwrite?'):
                    return
            self.saveTheme(newTheme)
项目:pymod    作者:pymodproject    | 项目源码 | 文件源码
def choose_psiblast_db_dir(self):
        """
        Called when users want to manually choose a BLAST sequence database folder on their system.
        """
        current_path = self.blast_plus["database_dir_path"].get_value()
        new_path = None
        # Lets users choose a new path.
        new_path = askdirectory(title = "Search for a BLAST database directory", initialdir=current_path, mustexist = True, parent = self.blast_window)
        if new_path:
            if pmos.verify_valid_blast_dbdir(new_path):
                prefix = pmos.get_blast_database_prefix(new_path)
                # Updates the label with the new prefix name.
                self.choose_path_label.configure(text=prefix)
                self.list_of_databases_directories[0]["full-path"] = new_path
            else:
                self.choose_path_label.configure(text="None")
                self.list_of_databases_directories[0]["full-path"] = None
                title = "Selection Error"
                message = "The directory you specified does not seem to contain a valid set of sequence database files."
                self.show_error_message(title, message, parent_window = self.blast_window, refresh=False)
        # Selects the 'browse' button once users click on it.
        self.psiblast_database_rds.setvalue("browse")
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def opendirectory():
    try:
        entry.delete(0, END)
        fileopen = tkFileDialog.askdirectory()
        entry.insert(END, fileopen)
    except:
        textbox.insert(END, "There was an error opening ")
        textbox.insert(END, fileopen)
        textbox.insert(END, "\n")
项目:XimaExport    作者:ryankomodo    | 项目源码 | 文件源码
def openDir(self):
        self.out_entry.delete(0,tk.END)
        dirname=askdirectory()
        self.out_entry.insert(tk.END,dirname)
        if len(dirname)>0:
            #print('Output folder: %s' %dirname)
            printch('?:')
        print('   '+dirname)
            self.hasout=True
            self.checkReady()
项目:androidtool    作者:oicebot    | 项目源码 | 文件源码
def browse_dir():
    print('androidtool_support.browse_dir')
    global file_path
    global files_list
    new_dir = tkFileDialog.askdirectory()
    #print(new_dir)
    if new_dir:
        file_path = new_dir
        os.walk(file_path)
        refresh_list(1)
项目:Scoary    作者:AdmiralenOla    | 项目源码 | 文件源码
def BrowseButtonClickOutput(self):
        """
        Browse button for choosing output dir
        """
        mydir = tkFileDialog.askdirectory(mustexist=True)
        self.Outputdir.set(mydir)
项目:Tweezer_design    作者:AntoineRiaud    | 项目源码 | 文件源码
def Create_group():
    Tk().withdraw()
    IDT_group = {'IDT': []}
    IDT_group_dir = tkFileDialog.askdirectory(title = 'Project_filename')
    IDT_group['IDT_group_dir'] = IDT_group_dir
    return IDT_group
项目:heartbreaker    作者:lokori    | 项目源码 | 文件源码
def selectDirectory(self,widget):
        if widget == self.sampledir:
            self.sampledir.textfield.config(state='enabled')
            self.inputfile.textfield.config(state='disabled')
        dirname = StringVar()
        dirname = askdirectory()
        if dirname:
            widget.textfield.delete(0,END)
            widget.textfield.insert(0,dirname)
            if len(dirname) > 40:
                widget.textfield.config(width = len(dirname))
项目:sendobox    作者:sendobox    | 项目源码 | 文件源码
def get_download_path():
    global download_path
    download_path = tkFileDialog.askdirectory()
    textbox_download_path.insert(INSERT, download_path)
项目:sendobox    作者:sendobox    | 项目源码 | 文件源码
def get_image_path():
    image_path = tkFileDialog.askdirectory()
    textbox_image_path.insert(INSERT, image_path)
项目:aurora-sdk-win    作者:nanoleaf    | 项目源码 | 文件源码
def get_plugin_dir(self):
        self.plugin_dir_path.set(tkFileDialog.askdirectory())
项目:wireless-network-reproduction    作者:FinalTheory    | 项目源码 | 文件源码
def load_dump_pos(self):
        dir_name, file_name = os.path.split(__file__)
        dir_name = os.path.join(dir_name, 'examples')
        dir_path = askdirectory(title='Choose dump position',
                                initialdir=dir_name)
        self.dump_pos.set(dir_path)
项目:rapidpythonprogramming    作者:thecount12    | 项目源码 | 文件源码
def diropenbox(msg=None
    , title=None
    , default=None
    ):
    """
    A dialog to get a directory name.
    Note that the msg argument, if specified, is ignored.

    Returns the name of a directory, or None if user chose to cancel.

    If the "default" argument specifies a directory name, and that
    directory exists, then the dialog box will start with that directory.
    """
    title=getFileDialogTitle(msg,title)      
    boxRoot = Tk()
    boxRoot.withdraw()
    if not default: default = None
    f = tk_FileDialog.askdirectory(
          parent=boxRoot
        , title=title
        , initialdir=default
        , initialfile=None
        )          
    boxRoot.destroy()     
    if not f: return None
    return os.path.normpath(f)



#-------------------------------------------------------------------
# getFileDialogTitle
#-------------------------------------------------------------------
项目:pkgdecrypt-frontend    作者:SilicaAndPina    | 项目源码 | 文件源码
def output():
    global outputFolder
    outputFolder = tkFileDialog.askdirectory(title='Output Folder')
    sys.stdout.flush()
项目:pymod    作者:pymodproject    | 项目源码 | 文件源码
def pymod_directory_browse_state(self):
        current_path = self.pymod_dir_window_main_entry.get()
        # Lets users choose a new path.
        new_path = askdirectory(title = "Select a folder in which to build the 'PyMod Directory'",
                                initialdir=current_path, mustexist = True, parent = self.pymod_dir_window)
        # Updates the text in the Entry with the new path name.
        if new_path:
            self.pymod_dir_window_main_entry.delete(0, END)
            self.pymod_dir_window_main_entry.insert(0, new_path)
项目:FunKii-UI    作者:dojafoja    | 项目源码 | 文件源码
def get_output_directory(self):
        out_dir=filedialog.askdirectory()
        self.out_dir_box.delete('0',tk.END)
        self.out_dir_box.insert('end',out_dir)
项目:Video-Downloader    作者:EvilCult    | 项目源码 | 文件源码
def __chooseCfgFolder (self) :
        path = tkFileDialog.askdirectory(initialdir="/",title='??????')
        self.filePath.set(path.strip())
项目:BeachedWhale    作者:southpaw5271    | 项目源码 | 文件源码
def directoryBox(self, title=None, dirName=None):
        self.topLevel.update_idletasks()
        options = {}
        options['initialdir'] = dirName
        options['title'] = title
        options['mustexist'] = False
        fileName = filedialog.askdirectory(**options)
        if fileName == "":
            return None
        else:
            return fileName
项目:SVPV    作者:VCCRI    | 项目源码 | 文件源码
def asksaveasfilename(self):
        if not self.parent.filename:
            self.parent.set_info_box(message='Error: No figure has been created yet.')
        else:
            file_options = {}
            file_options['initialdir'] = self.parent.par.run.out_dir
            file_options['initialfile'] = re.sub('/.+/', '', self.parent.filename)
            file_options['filetypes'] = [('pdf files', '.pdf')]
            file_options['parent'] = self.parent
            file_options['title'] = 'save figure as'
            filename = tkFileDialog.askdirectory(**file_options)
            if filename:
                copyfile(self.parent.filename, filename)
项目:SVPV    作者:VCCRI    | 项目源码 | 文件源码
def set_plot_all_dir(self):
        dir_options = {}
        dir_options['initialdir'] = self.par.run.out_dir
        dir_options['parent'] = self
        dir_options['title'] = 'select existing or type new directory'
        dir_options['mustexist'] = False
        path = tkFileDialog.askdirectory(**dir_options)
        if path == '':
            return None
        else:
            return path
项目:Python-Media-Player    作者:surajsinghbisht054    | 项目源码 | 文件源码
def ask_for_directory(self):
            path=tkFileDialog.askdirectory(title='Select Directory For Playlist')
            if path:
                    self.directory.set(path)
                    print (path)
                    return self.update_list_box_songs(dirs=path)
项目:Menotexport    作者:Xunius    | 项目源码 | 文件源码
def openDir(self):
        self.out_entry.delete(0,tk.END)
        dirname=askdirectory()
        self.out_entry.insert(tk.END,dirname)
        if len(dirname)>0:
            print('# <Menotexport>: Output folder: %s' %dirname)
            self.hasout=True
            self.checkReady()
项目:cms-dl    作者:nikhil-97    | 项目源码 | 文件源码
def askdir(self):
        # global directory
        Gui.directory=tkFileDialog.askdirectory(parent=root, mustexist=True)
        print "askdir"
        #if directory:
        #   self.directory_var.set(directory)
项目:pyry3d_chimera_extension    作者:mdobrychlop    | 项目源码 | 文件源码
def ig_choose_output_folder(self, parent, entry):
        outpath = tkFileDialog.askdirectory(
            parent=parent, initialdir="/", title="Choose output folder")
        entry.setvalue(outpath)
        entry.configure(entry_state="disabled")
        # outpath=outpath+"/input"
        return outpath
项目:pyry3d_chimera_extension    作者:mdobrychlop    | 项目源码 | 文件源码
def clust_input_set(self):
        path = tkFileDialog.askdirectory(
                parent=self.page5,
                initialdir=self.initialdir,
                title="Choose input folder"
                )
        self.p6_input_entry.setvalue(path)
        self.save_path(path)
项目:pyry3d_chimera_extension    作者:mdobrychlop    | 项目源码 | 文件源码
def clust_out_set(self):
        path = tkFileDialog.askdirectory(
            parent=self.page5,
            initialdir=self.initialdir,
            title="Choose output folder"
            )
        self.p6_output_entry.setvalue(path)
        self.save_path(path)
项目:pyry3d_chimera_extension    作者:mdobrychlop    | 项目源码 | 文件源码
def ranking_input_set(self):
        path = tkFileDialog.askdirectory(
                parent=self.page5,
                initialdir=self.initialdir,
                title="Choose input folder"
                )
        self.p5_input_entry.setvalue(path)
        self.save_path(path)
项目:pyry3d_chimera_extension    作者:mdobrychlop    | 项目源码 | 文件源码
def define_pyry3d_path(self, parent):
        """
        fossil, get rid of it
        """
        path = tkFileDialog.askdirectory(parent=parent, initialdir="/",
                                         title="Point the PyRy3D directory"
                                         )
        return path
项目:sas_kgp    作者:sairao210    | 项目源码 | 文件源码
def func6(self):
        #self.withdraw() #use to hide tkinter window
        currdir = os.getcwd()
        tempdir = tkFileDialog.askdirectory(parent=self, initialdir=currdir, title='Please select a directory')
        if len(tempdir) > 0:
            shutil.copy('attendence.xlsx', tempdir)
        else:
            pass
项目:sas_kgp    作者:sairao210    | 项目源码 | 文件源码
def func5(self,event):
        #self.withdraw() #use to hide tkinter window
        currdir = os.getcwd()
        tempdir = tkFileDialog.askdirectory(parent=self, initialdir=currdir, title='Please select a directory')
        if len(tempdir) > 0:
            shutil.copy('attendence.xlsx', tempdir)
        else:
            pass
        print('hey')
项目:sas_kgp    作者:sairao210    | 项目源码 | 文件源码
def func6(self,event):
        #self.withdraw() #use to hide tkinter window
        currdir = os.getcwd()
        tempdir = tkFileDialog.askdirectory(parent=self, initialdir=currdir, title='Please select a directory')
        if len(tempdir) > 0:
            shutil.copy('attendence.xlsx', tempdir)
        else:
            pass
        print('hey')
项目:sas_kgp    作者:sairao210    | 项目源码 | 文件源码
def func6(self,event):
        #self.withdraw() #use to hide tkinter window
        currdir = os.getcwd()
        tempdir = tkFileDialog.askdirectory(parent=self, initialdir=currdir, title='Please select a directory')
        if len(tempdir) > 0:
            shutil.copy('attendence.xlsx', tempdir)
        else:
            pass
        print('hey')
项目:SFC_models    作者:brianr747    | 项目源码 | 文件源码
def install_examples(): # pragma: no cover
    """
    Pops up windows to allow the user to choose a directory for installation
    of sfc_models examples.

    Uses tkinter, which is installed in base Python (modern versions).
    :return:
    """
    if not mbox.askokcancel(title='sfc_models Example Installation',
                            message=validate_str):
        return
    target = fdog.askdirectory(title='Choose directory to for sfc_models examples installation')
    if target == () or target == '':
        return
    install_example_scripts.install(target)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs):
        """
        Place the required elements using the grid layout method.

        Returns the number of rows taken by this element.
        """
        label = ttk.Label(master, text=self.text)
        label.grid(row=row, column=0, columnspan=1, sticky="e")
        self.entry = ttk.Entry(master, textvariable=self.value)
        self.entry.grid(row=row, column=1, columnspan=columns - 1, sticky="ew")
        if self.directory:
            self.choose = ttk.Button(master, text="Choose...",
                                     command=lambda:
                                     self.value.set(
                                        tkFileDialog.askdirectory()))
        else:
            self.choose = ttk.Button(master, text="Choose...",
                                     command=lambda:
                                     self.value.set(
                                         tkFileDialog.askopenfilename()))
        self.choose.grid(row=row + 1, column=1, sticky="w")
        if self.optional:
            self.clear = ttk.Button(master, text="Clear",
                                    command=lambda: self.value.set(""))
            self.clear.grid(row=row + 1, column=2, sticky="e")
        return 2
项目:Snakepit    作者:K4lium    | 项目源码 | 文件源码
def diropenbox(msg=None
    , title=None
    , default=None
    ):
    """
    A dialog to get a directory name.
    Note that the msg argument, if specified, is ignored.

    Returns the name of a directory, or None if user chose to cancel.

    If the "default" argument specifies a directory name, and that
    directory exists, then the dialog box will start with that directory.
    """
    title=getFileDialogTitle(msg,title)
    localRoot = Tk()
    localRoot.withdraw()
    if not default: default = None
    f = tk_FileDialog.askdirectory(
          parent=localRoot
        , title=title
        , initialdir=default
        , initialfile=None
        )
    localRoot.destroy()
    if not f: return None
    return os.path.normpath(f)



#-------------------------------------------------------------------
# getFileDialogTitle
#-------------------------------------------------------------------
项目:Huaban-images-download-with-Gui    作者:meishijie    | 项目源码 | 文件源码
def clickme1():
    """   # ?????acction????,??????"""
    global GPATH
    GPATH = ''
    path = tkFileDialog.askdirectory()
    if path:
        GPATH = path
        nameEntered1.delete(0, END)
        nameEntered1.insert(0, GPATH)
项目:pydiff    作者:yebrahim    | 项目源码 | 文件源码
def __load_directory(self, pos):
        dirName = askdirectory()
        if dirName:
            if pos == 'left':
                self.__main_window_ui.leftFileLabel.config(text=dirName)
            else:
                self.__main_window_ui.rightFileLabel.config(text=dirName)
            return dirName
        else:
            return None

    # Callback for changing a file path
项目:MetaXcan    作者:hakyimlab    | 项目源码 | 文件源码
def folderButtonPressed(self, button, must_exist):
        dir = tkFileDialog.askdirectory(mustexist=must_exist)
        if len(dir) == 0:
            return None
        rel = os.path.relpath(dir, self.cwd)
        button.config(text=rel)
        return rel
项目:PyKinectTk    作者:Qirky    | 项目源码 | 文件源码
def select_folder():
    root = Tk()
    root.withdraw()
    path = realpath(askdirectory(parent=root))  
    root.destroy()
    return path
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def diropenbox(msg=None
    , title=None
    , default=None
    ):
    """
    A dialog to get a directory name.
    Note that the msg argument, if specified, is ignored.

    Returns the name of a directory, or None if user chose to cancel.

    If the "default" argument specifies a directory name, and that
    directory exists, then the dialog box will start with that directory.
    """
    title=getFileDialogTitle(msg,title)
    boxRoot = Tk()
    boxRoot.withdraw()
    if not default: default = None
    f = tk_FileDialog.askdirectory(
          parent=boxRoot
        , title=title
        , initialdir=default
        , initialfile=None
        )
    boxRoot.destroy()
    if not f: return None
    return os.path.normpath(f)



#-------------------------------------------------------------------
# getFileDialogTitle
#-------------------------------------------------------------------
项目:bruker2nifti    作者:SebastianoF    | 项目源码 | 文件源码
def button_browse_callback_pfo_input(self):
        filename = tkFileDialog.askdirectory()
        self.entry_pfo_input.delete(0, tk.END)
        self.entry_pfo_input.insert(0, filename)
项目:bruker2nifti    作者:SebastianoF    | 项目源码 | 文件源码
def button_browse_callback_pfo_output(self):
        filename = tkFileDialog.askdirectory()
        self.entry_pfo_output.delete(0, tk.END)
        self.entry_pfo_output.insert(0, filename)
项目:aurora-sdk-mac    作者:nanoleaf    | 项目源码 | 文件源码
def get_plugin_dir(self):
        self.plugin_dir_path.set(tkFileDialog.askdirectory())
项目:SceneDensity    作者:ImOmid    | 项目源码 | 文件源码
def directoryBox(self, title=None, dirName=None):
        self.topLevel.update_idletasks()
        options = {}
        options['initialdir'] = dirName
        options['title'] = title
        options['mustexist'] = False
        fileName = filedialog.askdirectory(**options)
        if fileName == "":
            return None
        else:
            return fileName
项目:animeDown    作者:ekistece    | 项目源码 | 文件源码
def main():
    #display search menu
    result = SearchInput()

    #show found series
    choice = DisplayResult(result)

    #get title and episode objects
    title = result[choice].name
    episodes = GetEpisodes(result[choice].url)
    numEpisodes = len(episodes)

    #create directory for saving anime

    w = Tkinter.Tk()
    w.withdraw()

    path = tkFileDialog.askdirectory()

    if not os.path.exists(path):
        print '[!] Error, quitting!'
        return

    #Bugfix for naming folders on windows
    folderName = title.translate(None, '"<>:/\\|?*')

    #Creating the folder
    savePath = os.path.join(path, folderName)
    if not os.path.exists(savePath):
        os.mkdir(savePath)

    #create Mega downloader object
    mega = Mega({'verbose': True})

    #Starting download...
    Clear()
    print version
    print '[*] Downloading ' + title + ' in ' + savePath
    print '[*] ' + str(numEpisodes) + ' episodes waiting for download...'

    #iterate through episodes list and download
    count = 0
    for episode in episodes:
        print '[*] Episode number ' + str(episode.num) + ' downloading...'
        try:
            mega.download_url(episode.url, savePath)
            print '[*] Episode ' + str(episode.num) + ' downloaded!'
            count = count + 1
        except:
            print '[!] Error! Could not download! Skipping!'

    #Finish and exit if no errors
    print '[*] ' + str(count) + ' chapters downloaded successfully!'
    raw_input()
    return
项目:xbmctopython    作者:pybquillast    | 项目源码 | 文件源码
def browse(self, type, heading, s_shares, mask=None, useThumbs=False, treatAsFolder=False, default=None,
               enableMultiple=False):
        """Show a 'Browse' dialog.

        type: integer - the type of browse dialog.
        heading: string or unicode - dialog heading.
        s_shares: string or unicode - from sources.xml. (i.e. 'myprograms')
        mask: string or unicode - '|' separated file mask. (i.e. '.jpg|.png')
        useThumbs: boolean - if True autoswitch to Thumb view if files exist.
        treatAsFolder: boolean - if True playlists and archives act as folders.
        default: string - default path or file.
        enableMultiple: boolean - if True multiple file selection is enabled.

        Types:
            0: ShowAndGetDirectory
            1: ShowAndGetFile
            2: ShowAndGetImage
            3: ShowAndGetWriteableDirectory

        Note:
            If enableMultiple is False (default): returns filename and/or path as a string
            to the location of the highlighted item, if user pressed 'Ok' or a masked item
            was selected. Returns the default value if dialog was canceled.
            If enableMultiple is True: returns tuple of marked filenames as a string,
            if user pressed 'Ok' or a masked item was selected. Returns empty tuple if dialog was canceled.

            If type is 0 or 3 the enableMultiple parameter is ignored.

        Example:
            dialog = xbmcgui.Dialog()
            fn = dialog.browse(3, 'XBMC', 'files', '', False, False, False, 'special://masterprofile/script_data/XBMC Lyrics')
        """
        root = self.root
        default = xbmc.translatePath(default)
        initDir, initFile = os.path.split(default)
        if type in [0, 3]:        # ShowAndGetDirectory, ShowAndGetWriteableDirectory
            answ = tkFileDialog.askdirectory(title=heading, initialdir= initDir, mustexist=True)
            pass
        elif type == 1:     # ShowAndGetFile
            answ = tkFileDialog.askopenfilename(defaultextension = '', filetypes=[('req files', mask or '.txt')], initialdir=initDir, initialfile=initFile, multiple=enableMultiple, title=heading)
            pass
        elif type == 2:     # ShowAndGetImage
            mask = '.png|.jpg|.jpeg|.bmp|.gif|.ico|.tif|.tiff|.tga|.pcx|.cbz|.zip|.cbr|.rar|.dng|.nef|.cr2|.crw|.orf|.arw|.erf|.3fr|.dcr|.x3f|.mef|.raf|.mrw|.pef|.sr2|.rss'
            answ = tkFileDialog.askopenfilename(defaultextension = '.png', filetypes=[('image files', mask), ('all files', '.txt')], initialdir=initDir, initialfile=initFile, multiple=enableMultiple, title=heading)
            pass
        return answ