我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用tkinter.filedialog.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 chooseDialogFiles(self): filenames = filedialog.askopenfilenames( defaultextension = '.SPE', filetypes = [('WinViewer Documents', '.SPE'), ('all files', '.*'),], parent = self, title = "Select .SPE files", multiple = True, ) print(filenames) if len(filenames) == 0: return self.chooseFilePath = os.path.dirname( os.path.realpath(filenames[0]) ) print("select:", self.chooseFilePath) self.chooseFileOutDir = filedialog.askdirectory( initialdir = self.chooseFilePath, parent = self, title = "Select output Directory", mustexist = False, ) print("out:", self.chooseFileOutDir) if not self.checkDir(self.chooseFileOutDir): return self.convertFiles(filenames, self.chooseFileOutDir)
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 chooseDialogDir(self): self.chooseDirPath = filedialog.askdirectory( initialdir = self.chooseDirPath, parent = self, title = "Select Directory contains .SPE files", ) print("select:", self.chooseDirPath) if len(self.chooseDirPath) == 0: return self.chooseDirOutDir = filedialog.askdirectory( initialdir = self.chooseDirPath, parent = self, title = "Select output Directory", mustexist = False, ) # TODO check wirte permission first if not self.checkDir(self.chooseDirOutDir): return filenames = yieldFilesUnderDirectory(self.chooseDirPath, match = "*.SPE") if filenames is None: messagebox.showinfo("Convert result", "No .SPE files under this directory") return self.convertFiles(filenames, self.chooseDirOutDir, oldPrefix = self.chooseDirPath)
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
def open_pack(self): pack = filedialog.askdirectory(initialdir=self.resourcepack_location) if os.path.isfile(pack + "/pack.mcmeta"): # messagebox.showinfo("Information", "Found 'pack.mcmeta'.") self.parent.directory = pack self.parent.cmd.tree_refresh() self.destroy() else: messagebox.showerror("Error", "Could not find 'pack.mcmeta'.")
def install_pack(self): pack = filedialog.askdirectory() if os.path.isfile(pack + "/pack.mcmeta"): # messagebox.showinfo("Information", "Found 'pack.mcmeta'.") try: shutil.move(pack, self.resourcepack_location) except shutil.Error: messagebox.showerror("Error", "This pack is already installed.") else: messagebox.showerror("Error", "Could not find 'pack.mcmeta'.")
def select_folder(): from tkinter import filedialog selected = filedialog.askdirectory(initialdir=getcwd(), title='Select IVS Data Folder') _folderVar.set(selected) print('Selected data folder: {}'.format(_folderVar.get()))
def select_export(): selected = filedialog.askdirectory(initialdir=getcwd(), title='Select Export Tables Folder') _tableFolderVar.set(selected) print('Selected export table folder: {}'.format(_tableFolderVar.get()))
def get_save_path(): Data.save_path = askdirectory() chosen_save_path_label["text"] = Data.save_path return Data.save_path
def addListenDir(self): listenDirPath = filedialog.askdirectory( parent = self, title = "Auto convert (listen) .spe under this directory", initialdir = self.listenDirPath.get(), ) if not self.checkDir(listenDirPath, autocreate = False, poperror = False): return print("listen:", listenDirPath) if os.path.abspath(listenDirPath) != self.listenDirPath.get(): self.listenDirPath.set(os.path.abspath(listenDirPath)) self.checkListenTask()
def bindListenDir(self): newOutDir = filedialog.askdirectory( parent = self, title = "Auto convert .spe into this directory", initialdir = self.listenDirPath.get(), ) if not self.checkDir(newOutDir, autocreate = False, poperror = False): return print("bind to:", newOutDir) self.listenDirOutputPath.set(os.path.abspath(newOutDir))
def _browse(self): """Opens a directory browser.""" directory = filedialog.askdirectory(initialdir=self._directory) self._variable.set(directory)
def on_select_plugins_folder(self, *args): _plugin_folder = filedialog.askdirectory(title="Choose plugin folder (usually in the ") if _plugin_folder is not None or _plugin_folder != "": self.plugins_folder.set(_plugin_folder)
def on_select_install_folder(self, *args): _install_folder = filedialog.askdirectory(title="Choose install folder (usually in the \"~of\"-folder)") if _install_folder is not None or _install_folder != "": self.install_location.set(_install_folder)
def on_select_installation(self, *args): _install_folder = filedialog.askdirectory(title="Select existing installation") if _install_folder is not None or _install_folder != "": self.install_location.set(_install_folder) self.setup.load_install(_install_folder=_install_folder) self.setup_to_gui()
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 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 select_path(self): file_path = askdirectory() self.file_path_var.set(file_path)
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 browse(self): filename= askdirectory() #print (filename) for exe in os.listdir(filename): if exe.endswith(".exe"): executabile=exe print (executabile) command='netsh advfirewall firewall add rule name="Block {}" dir=in action=block program="{}" enable=yes'.format(executabile,executabile) subprocess.call(command,shell=True)
def main(): user_folder = os.getenv("USERPROFILE") nier_automata_folder = path.join(user_folder, "Documents", "My Games", "NieR_Automata") if not path.isdir(nier_automata_folder): messagebox.showerror("Error", "Could not find Nier;Automata's save folder location. Please select the save folder location") nier_automata_folder = filedialog.askdirectory() gamedata_path = path.join(nier_automata_folder, "GameData.dat") if not path.isfile(gamedata_path): raise Exception("Could not find NieR_Automata/GameData.dat. Please run Nier;Automata at least once before using this tool.") # read the gamedata header. with open(gamedata_path, "rb") as f: gamedata_header = f.read(12) locations = ("SlotData_0.dat", "SlotData_1.dat", "SlotData_2.dat") import collections saves = collections.OrderedDict() for location in locations: savedata_path = path.join(nier_automata_folder, location) if path.isfile(savedata_path): saves[location] = SaveGame(savedata_path) interface = Interface(saves, gamedata_header) interface.master.title("NieR;Automata Save Editor") interface.mainloop()
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 set_directory(self, variable): """Return a selected directory name. ARGS: variable (tk.Variable): The tkinter variable to save selection as. """ selection = filedialog.askdirectory(**self.directory_options) variable.set(selection)
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 _show_diag(self, text): dir_ = filedialog.askdirectory() if dir_: if text == 'source': self.source_entry.delete(0, END) self.source_entry.insert(0, dir_) if text == 'destination': self.dst_entry.delete(0, END) self.dst_entry.config(state='normal') self.dst_entry.insert(0, dir_)
def bit_dir_open(self, gs): """Open filedialog when Select Location of Files button selected.""" self.bit_dir_path = filedialog.askdirectory() gs.bit_path = self.bit_dir_path self.bit_dir_var.set(self.bit_dir_path)
def archive_dir_open(self, gs): """Open filedialog when Select Archive Destination button selected.""" self.archive_dir_path = filedialog.askdirectory() gs.archive_path = self.archive_dir_path self.archive_dir_var.set(self.archive_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) 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 setUp(self): self.o_aof = filedialog.askopenfilename self.o_ad = filedialog.askdirectory self.o_input = builtins.input self.settings = Settings()
def tearDown(self): filedialog.askopenfilename = self.o_aof filedialog.askdirectory = self.o_ad builtins.input = self.o_input
def test_get_path_gui(self): # Setup filedialog.askdirectory = lambda title: 'test_path' # Test self.assertEqual(ask_path_gui('test message', self.settings, get_file=False), 'test_path')
def test_no_path_raises_fr(self): # Setup filedialog.askdirectory = lambda title: '' # Test self.assertFR("Path selection aborted.", ask_path_gui, 'test message', self.settings, False)
def ask_path_gui(prompt_msg: str, settings: Union['Settings', 'nhSettings'], get_file: bool = False) -> str: """Prompt (file) path with Tkinter / CLI prompt. :param prompt_msg: Directory selection prompt :param settings: Settings object :param get_file: When True, prompts for path to file instead of directory :return: Selected directory / file """ try: if settings.disable_gui_dialog: raise _tkinter.TclError root = Tk() root.withdraw() if get_file: file_path = filedialog.askopenfilename(title=prompt_msg) else: file_path = filedialog.askdirectory(title=prompt_msg) root.destroy() if not file_path: raise FunctionReturn(("File" if get_file else "Path") + " selection aborted.") return file_path except _tkinter.TclError: return ask_path_cli(prompt_msg, get_file)
def open_folder(self): self.button_run['state'] = 'disabled' self.top_dir = filedialog.askdirectory(initialdir='.') self.label_path['text'] = 'Looking for images to optimize... Please, wait' self._start_count_images()
def save(): if not config.get('images'): _alert('No images to save') return if _save_method.get() == 'img': dirname = filedialog.askdirectory(mustexist=True) _save_images(dirname) else: filename = filedialog.asksaveasfilename( initialfile='images.json', filetypes=[('JSON', '.json')]) _save_json(filename)
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 hashcatdownloadfunc(): #GIT CLONES AND MAKE-BUILDs HASHCAT! import os, webbrowser, time from tkinter import filedialog from tkinter import Tk os.system("clear") print("""\033[0;33;48m a a aaa aaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaafaaaaaaafaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaa aaaaaaa aaaaaaaaaaaaaa a aaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa ??? ??? ?????? ??????????? ??? ??????? ?????? ????????? ??? ?????????????????????? ???????????????????????????? ??????????????????????????????????? ???????? ??? ??????????????????????????????????? ???????? ??? ??? ?????? ?????????????? ?????????????? ??? ??? ??? ?????? ?????????????? ??? ?????????? ??? ??? \033[0;39;48m """) if input("\033[1;39;48mDownload and setup hashcat for GPU-WPA cracking? [y/n] >> ").lower().startswith("y"): os.system("clear") print("\nWhere would you like hashcat installed?") input("\n|MENU|POST_CRACK|GPU|HASHCAT_DOWNLOAD|(Please delete any older versions and press enter to choose directory) >>") global hashpath Tk().withdraw() hashpath = filedialog.askdirectory() hashpath = str(hashpath) print("\nA browser window will now open. ALT+TAB back to the terminal") time.sleep(3) webbrowser.open("https://hashcat.net/") #print("Please right-click and copy/paste link location on the button next to hashcat binaries") downloadpath = input("\nPlease paste the URL/ADDRESS/LINK-LOCATION of the hashcat binaries download button EG:https://hashcat.net/files/hashcat-3.6.0.7z \033[1;31;48m~# \033[0;39;48m") os.system("sudo apt install p7zip p7zip-full -y;cd %s;wget %s;7z x hashcat-*;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath, downloadpath)) #os.system("cd %s;git clone https://github.com/hashcat/hashcat.git;cd hashcat/;git submodule update --init;make;cd ..;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath)) os.system("\necho '\033[1;32;48m[+] \033[1;39;48mHashcat is now ready to use, it will be inside the folder you chose \033[0;39;48m' ") os._exit(1) else: title()
def drifunc(): #Installs downloaded drivers import os from tkinter.filedialog import askopenfilename, Tk as snak snak().withdraw() def Nvidia(): os.system("clear") global nvenc path = input("Please select where the NVIDIA driver file is located. Press enter (you may have to answer yes to some options) \033[1;31;48m~# \033[0;39;48m") nvenc = askopenfilename() nvenc = str(nvenc) os.system("clear") input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|NVIDIA|(Please remove any previous drivers/driver downloads and hit enter) \033[1;31;48m~# \033[0;39;48m") os.system("cd %s;sudo ./NVIDIA-Linux*" %(nvenc)) print("echo NVIDIA driver is installed!") print("now reboot, if you see any error, please head to: 'https://goo.gl/f1GU1F'") def AMD(): os.system("clear") from tkinter import filedialog from tkinter import Tk global AMDlol AMDlol = input("Please select the folder where the AMD driver tar.xz file is located. Press enter \033[1;31;48m~# \033[0;39;48m") AMDlol = filedialog.askdirectory() AMDlol = str(AMDlol) os.system("clear") input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|AMD|(Please remove any previous drivers/driver downloads and hit enter) \033[1;31;48m~# \033[0;39;48m") os.system("cd %s;tar -Jxvf amdgpu-pro*;cd amdgpu-pro*;./amdgpu-pro-install -y" %(AMDlol)) print("echo AMD driver is installed!") print("now reboot, if you see any error, type: 'amdgpu-pro-uninstall' and reboot.") print(""" ??????? ???????????????????? ?????? ??? ??? ??????? ??????? ?????? ?????????????????? ???????? ???????? ??????????????????????????????? ??? ?????????????????????? ??????????????????????????? ????????? ??????????? ??? ??????????? ??? ??? ????????????????? ????????? ???????????????? ????????????????????? ??? ??????????? ??? ??? ?????????????????? ?????????? ???????????????? ?????? ?????????????? ??? ??? ??????????????????? ??????????? ?????? ??????? ??????????? ??????????? ?????? ????????????? ??? ??? ??????????????????? ??????? ??? ?????? ????? ??????????? ??????????? """) print("This is the driver installation screen. Your options are:") print("\n\n\033[1;35;48mType [1] - Install the NVIDIA-LINUX driver for Hashcat (NVIDIA GTX 900,10 Series)") print("\033[1;34;48mType [2] - Install the AMDGPU-PRO driver to use Hashcat with an AMD gpu (MOST GPUs, check hashcat.net)") sel = input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|(Type number) >>") if sel == "": drifunc() if sel == "1": Nvidia() if sel == "2": AMD()
def hashcatdownloadfunc(): #GIT CLONES AND MAKE-BUILDs HASHCAT! import os, webbrowser, time from tkinter import filedialog from tkinter import Tk os.system("clear") print(""" a a aaa aaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaafaaaaaaafaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaa aaaaaaa aaaaaaaaaaaaaa a aaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaaaa aaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa ??? ??? ?????? ??????????? ??? ??????? ?????? ????????? ??? ?????????????????????? ???????????????????????????? ??????????????????????????????????? ???????? ??? ??????????????????????????????????? ???????? ??? ??? ?????? ?????????????? ?????????????? ??? ??? ??? ?????? ?????????????? ??? ?????????? ??? ??? """) if input("Download and setup hashcat for GPU-WPA cracking? [y/n] >> ").lower().startswith("y"): os.system("clear") print("\nWhere would you like hashcat installed?") input("\n|MENU|POST_CRACK|GPU|HASHCAT_DOWNLOAD|(Please delete any older versions and press enter to choose directory) >>") global hashpath Tk().withdraw() hashpath = filedialog.askdirectory() hashpath = str(hashpath) print("\nA browser window will now open. ALT+TAB back to the terminal") time.sleep(3) webbrowser.open("https://hashcat.net/") #print("Please right-click and copy/paste link location on the button next to hashcat binaries") downloadpath = input("\nPlease paste the URL/ADDRESS/LINK-LOCATION of the hashcat binaries download button EG:https://hashcat.net/files/hashcat-3.6.0.7z ~# ") os.system("sudo apt install p7zip p7zip-full -y;cd %s;wget %s;7z x hashcat-*;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath, downloadpath)) #os.system("cd %s;git clone https://github.com/hashcat/hashcat.git;cd hashcat/;git submodule update --init;make;cd ..;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath)) os.system("\necho '[+] Hashcat is now ready to use, it will be inside the folder you chose ' ") os._exit(1) else: title()
def drifunc(): #Installs downloaded drivers import os from tkinter.filedialog import askopenfilename, Tk as snak snak().withdraw() def Nvidia(): os.system("clear") global nvenc path = input("Please select where the NVIDIA driver file is located. Press enter (you may have to answer yes to some options) ~# ") nvenc = askopenfilename() nvenc = str(nvenc) os.system("clear") input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|NVIDIA|(Please remove any previous drivers/driver downloads and hit enter) ~# ") os.system("cd %s;sudo ./NVIDIA-Linux*" %(nvenc)) print("echo NVIDIA driver is installed!") print("now reboot, if you see any error, please head to: 'https://goo.gl/f1GU1F'") def AMD(): os.system("clear") from tkinter import filedialog from tkinter import Tk global AMDlol AMDlol = input("Please select the folder where the AMD driver tar.xz file is located. Press enter ~# ") AMDlol = filedialog.askdirectory() AMDlol = str(AMDlol) os.system("clear") input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|AMD|(Please remove any previous drivers/driver downloads and hit enter) ~# ") os.system("cd %s;tar -Jxvf amdgpu-pro*;cd amdgpu-pro*;./amdgpu-pro-install -y" %(AMDlol)) print("echo AMD driver is installed!") print("now reboot, if you see any error, type: 'amdgpu-pro-uninstall' and reboot.") print(""" ??????? ???????????????????? ?????? ??? ??? ??????? ??????? ?????? ?????????????????? ???????? ???????? ??????????????????????????????? ??? ?????????????????????? ??????????????????????????? ????????? ??????????? ??? ??????????? ??? ??? ????????????????? ????????? ???????????????? ????????????????????? ??? ??????????? ??? ??? ?????????????????? ?????????? ???????????????? ?????? ?????????????? ??? ??? ??????????????????? ??????????? ?????? ??????? ??????????? ??????????? ?????? ????????????? ??? ??? ??????????????????? ??????? ??? ?????? ????? ??????????? ??????????? """) print("This is the driver installation screen. Your options are:") print("\n\nType [1] - Install the NVIDIA-LINUX driver for Hashcat (NVIDIA GTX 900,10 Series)") print("Type [2] - Install the AMDGPU-PRO driver to use Hashcat with an AMD gpu (MOST GPUs, check hashcat.net)") sel = input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|(Type number) >>") if sel == "": drifunc() if sel == "1": Nvidia() if sel == "2": AMD()