我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用tkFileDialog.askdirectory()。
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
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()
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
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)
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")
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")
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()
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)
def BrowseButtonClickOutput(self): """ Browse button for choosing output dir """ mydir = tkFileDialog.askdirectory(mustexist=True) self.Outputdir.set(mydir)
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
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))
def get_download_path(): global download_path download_path = tkFileDialog.askdirectory() textbox_download_path.insert(INSERT, download_path)
def get_image_path(): image_path = tkFileDialog.askdirectory() textbox_image_path.insert(INSERT, image_path)
def get_plugin_dir(self): self.plugin_dir_path.set(tkFileDialog.askdirectory())
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)
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 #-------------------------------------------------------------------
def output(): global outputFolder outputFolder = tkFileDialog.askdirectory(title='Output Folder') sys.stdout.flush()
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)
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)
def __chooseCfgFolder (self) : path = tkFileDialog.askdirectory(initialdir="/",title='??????') self.filePath.set(path.strip())
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)
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
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)
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()
def askdir(self): # global directory Gui.directory=tkFileDialog.askdirectory(parent=root, mustexist=True) print "askdir" #if directory: # self.directory_var.set(directory)
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
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)
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)
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)
def define_pyry3d_path(self, parent): """ fossil, get rid of it """ path = tkFileDialog.askdirectory(parent=parent, initialdir="/", title="Point the PyRy3D directory" ) return path
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
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')
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')
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)
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
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 #-------------------------------------------------------------------
def clickme1(): """ # ?????acction????,??????""" global GPATH GPATH = '' path = tkFileDialog.askdirectory() if path: GPATH = path nameEntered1.delete(0, END) nameEntered1.insert(0, GPATH)
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
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
def select_folder(): root = Tk() root.withdraw() path = realpath(askdirectory(parent=root)) root.destroy() return path
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)
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)
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
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