Python tkinter.filedialog.askdirectory() Examples

The following are 30 code examples of tkinter.filedialog.askdirectory(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tkinter.filedialog , or try the search function .
Example #1
Source File: extract_face_view.py    From rabbitVE with GNU General Public License v3.0 13 votes vote down vote up
def openfile(self, event):
        if event.widget["text"] == "..":
            intput_type = self.input_type.get()
            if not intput_type:
                messagebox.showerror("Error", "please select the input type first.")
                return
            if intput_type == "video":
                self.input_filename = askopenfilenames(title='select', filetypes=[
                    ("all video format", ".mp4"),
                    ("all video format", ".flv"),
                    ("all video format", ".avi"),
                ])
            elif intput_type == "image":
                self.input_filename = askopenfilenames(title='select', filetypes=[
                    ("image", ".jpeg"),
                    ("image", ".png"),
                    ("image", ".jpg"),
                ])
            self.label0_["text"] = self.input_filename
        elif event.widget["text"] == "...":
            self.output_dir = askdirectory(title="select")
            self.label1_["text"] = self.output_dir 
Example #2
Source File: functions_preparation.py    From javsdt with MIT License 9 votes vote down vote up
def choose_directory():
    directory_root = Tk()
    directory_root.withdraw()
    path_work = filedialog.askdirectory()
    if path_work == '':
        print('你没有选择目录! 请重新选:')
        sleep(2)
        return choose_directory()
    else:
        # askdirectory 获得是 正斜杠 路径C:/,所以下面要把 / 换成 反斜杠\
        return path_work.replace('/', sep)


# 功能:检查 归类根目录 的合法性
# 参数:用户自定义的归类根目录,用户选择整理的文件夹路径
# 返回:归类根目录路径
# 辅助:os.sep,os.system 
Example #3
Source File: dialog.py    From guizero with BSD 3-Clause "New" or "Revised" License 8 votes vote down vote up
def select_folder(title="Select folder", folder=".", master=None):
    """
    Display a box to select a folder.

    If a folder is selected the folder path is returned, otherwise `None` is returned.

    :param string title:
        The title to be displayed on the box. Defaults to 'Select file'.
    :param string folder:
        The initial folder to open. Defaults to '.'.
    :param App master:
        Optional guizero master which the popup will be placed over. Defaults
        to `None`.
    :return:
        The path of folder selected or `None`.
    """
    if not os.path.isdir(folder):
        utils.error_format("The folder '{}' specified for select_folder does not exist.".format(folder))
        folder = "."
    
    return filedialog.askdirectory(title=title, initialdir=folder, parent=None if master is None else master.tk) 
Example #4
Source File: labelling_aggression.py    From simba with GNU Lesser General Public License v3.0 7 votes vote down vote up
def choose_folder(project_name):
    global current_video, projectini
    projectini = project_name
    img_dir = filedialog.askdirectory()
    os.chdir(img_dir)
    dirpath = os.path.basename(os.getcwd())
    current_video = dirpath
    print('Current Video: ' + current_video)

    global frames_in
    frames_in = []
    for i in os.listdir(os.curdir):
        if i.__contains__(".png"):
            frames_in.append(i)
        reset()

    frames_in = sorted(frames_in, key=lambda x: int(x.split('.')[0]))
    # print(frames_in)
    number_of_frames = len(frames_in)
    print("Number of Frames: " + str(number_of_frames))

    configure(project_name)

    MainInterface()
    #create_data_frame(number_of_frames) 
Example #5
Source File: toolkit.py    From PickTrue with MIT License 6 votes vote down vote up
def choose_file(self):
        path = filedialog.askdirectory(
            title="选择下载文件夹",
        )
        if not path:
            return
        path = Path(path)
        self.label_text.set(str(path))
        if self._config is not None:
            self._config.op_store_path(self._store_name, path) 
Example #6
Source File: process.py    From selective_copy with MIT License 6 votes vote down vote up
def select_destination(self):
        """
        Check if the destination path is in the command line arguments,
        if not ask user for input using filedialog.
        If the destination path in arguments does not exist create it.
        :return: str. Destination folder path.
        """
        if self.args.dstcwd:
            destination = os.getcwd()
        else:
            if self.args.dest is None:
                print("Choose a destination path.")
                destination = os.path.normpath(askdirectory())
                print(f"Destination path: {destination}")
            else:
                destination = self.args.dest
                if not os.path.exists(destination):
                    os.makedirs(destination)
        return destination 
Example #7
Source File: process.py    From selective_copy with MIT License 6 votes vote down vote up
def select_source(self):
        """
        Check if the source path is in the command line arguments,
        if not ask user for input using filedialog.
        :return: str. Source folder path.
        """
        if self.args.srccwd:
            source = os.getcwd()
        else:
            if self.args.source is None:
                print("Choose a source path.")
                source = os.path.normpath(askdirectory())
                print(f"Source path: {source}")
            else:
                source = self.args.source
        return source 
Example #8
Source File: CDNSP-GUI-Bob.py    From CDNSP-GUI with GNU General Public License v3.0 5 votes vote down vote up
def unlock_nsx(self):
        path = self.normalize_file_path(filedialog.askdirectory())
        self.unlock_nsx_gui.lift()
        self.unlock_nsx_gui.update()
        self.dir_entry_nsx.delete(0, END)
        self.dir_entry_nsx.insert(0, path) 
Example #9
Source File: main_gui.py    From tf-idf-python with MIT License 5 votes vote down vote up
def open_filedialog():
    global folder
    folder = tkfd.askdirectory(initialdir=os.path.dirname(__file__) + '/..', )
    entry_dir_name.delete(0, tk.END)
    entry_dir_name.insert(0, folder)
    print(folder)
    return 0 
Example #10
Source File: ListPanel.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
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) 
Example #11
Source File: entry.py    From tts-backup with GNU General Public License v3.0 5 votes vote down vote up
def ask(self):

        dirname = filedialog.askdirectory(initialdir=self.initialdir,
                                          mustexist=self.mustexist)
        self.var.set(dirname) 
Example #12
Source File: video_merge_view.py    From rabbitVE with GNU General Public License v3.0 5 votes vote down vote up
def openfile(self, event):
        if event.widget["text"] == "...":
            self.video_dir = askdirectory(title="select")
            self.label0_["text"] = self.video_dir

        if event.widget["text"] == "..":
            self.save_file = asksaveasfilename(title="save", filetypes=[
                ("all video format", ".mp4"),
                ("all video format", ".flv"),
                ("all video format", ".avi"),
            ], initialfile="result.mp4")
            self.label1_["text"] = self.save_file 
Example #13
Source File: main.py    From BBox-Label-Tool with MIT License 5 votes vote down vote up
def selectSrcDir(self):
        path = filedialog.askdirectory(title="Select image source folder", initialdir=self.svSourcePath.get())
        self.svSourcePath.set(path)
        return 
Example #14
Source File: main.py    From BBox-Label-Tool with MIT License 5 votes vote down vote up
def selectDesDir(self):
        path = filedialog.askdirectory(title="Select label output folder", initialdir=self.svDestinationPath.get())
        self.svDestinationPath.set(path)
        return 
Example #15
Source File: gui_elements.py    From Airscript-ng with GNU General Public License v3.0 5 votes vote down vote up
def pickDirectory():
    while True:
        dirPath = filedialog.askdirectory()
        if dirPath is None:
            continue
        elif str(dirPath) in ["()",""]:
            continue
        else:
            return str(dirPath)
#Define function to choose file 
Example #16
Source File: gui.py    From OverwatchDataAnalysis with GNU General Public License v3.0 5 votes vote down vote up
def click_save(self):
        filename = filedialog.askdirectory(initialdir='~/')
        self.save_path.config(text=filename) 
Example #17
Source File: clip_view.py    From rabbitVE with GNU General Public License v3.0 5 votes vote down vote up
def openfile(self, event):
        if event.widget["text"] == "..":
            self.input_filename = askopenfilename(title='select', filetypes=[
                ("all video format", ".mp4"),
                ("all video format", ".flv"),
                ("all video format", ".avi"),
            ])

            self.label0_["text"] = self.input_filename
        elif event.widget["text"] == "...":
            self.output_dir = askdirectory(title="select")
            self.label1_["text"] = self.output_dir
        elif event.widget["text"] == "....":
            self.face_dir = askdirectory(title="select")
            self.label_face_["text"] = self.face_dir 
Example #18
Source File: utils.py    From faceswap with GNU General Public License v3.0 5 votes vote down vote up
def _dir(self):
        """ Get a directory location. """
        logger.debug("Popping Dir browser")
        return filedialog.askdirectory(**self._kwargs) 
Example #19
Source File: CDNSP-GUI-Bob.py    From CDNSP-GUI with GNU General Public License v3.0 5 votes vote down vote up
def my_game_directory(self):
        path = self.normalize_file_path(filedialog.askdirectory())
        if path != "":
            self.game_location = path
            updateJsonFile("Game_location", str(self.game_location))
        self.my_game.lift()
        self.my_game.update()
        self.dir_entry.delete(0, END)
        self.dir_entry.insert(0, path) 
Example #20
Source File: CDNSP-GUI-Bob.py    From CDNSP-GUI with GNU General Public License v3.0 5 votes vote down vote up
def change_nsp_path(self):
        global nsp_location
        path = self.normalize_file_path(filedialog.askdirectory())
        nsp_location = path
        
        updateJsonFile("NSP_location", path)
        print("\nNSP Location: {}".format(path)) 
Example #21
Source File: CDNSP-GUI-Bob.py    From CDNSP-GUI with GNU General Public License v3.0 5 votes vote down vote up
def change_dl_path(self):
        self.path = self.normalize_file_path(filedialog.askdirectory())

        updateJsonFile("Download_location", self.path)
        print("\nDownload Location:{}".format(self.path)) 
Example #22
Source File: pdfviewer.py    From pdfviewer with MIT License 5 votes vote down vote up
def _open_dir(self):
        dir_name = filedialog.askdirectory(initialdir=os.getcwd(), title="Select Directory Containing Invoices")
        if not dir_name or dir_name == '':
            return
        paths = os.listdir(dir_name)
        paths = [os.path.join(dir_name, path) for path in paths
                 if os.path.basename(path).split('.')[-1].lower() in ['pdf', 'jpg', 'png']]
        self.paths.extend(paths)
        if not self.paths:
            return
        self.total_pages = len(self.paths)
        self.pathidx += 1
        self._load_file() 
Example #23
Source File: main.py    From bifacial_radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _interactive_directory(title=None):
    # Tkinter directory picker.  Now Py3.6 compliant!
    import tkinter
    from tkinter import filedialog
    root = tkinter.Tk()
    root.withdraw() #Start interactive file input
    root.attributes("-topmost", True) #Bring to front
    return filedialog.askdirectory(parent=root, title=title) 
Example #24
Source File: app.py    From captcha_trainer with Apache License 2.0 5 votes vote down vote up
def browse_dataset(self, dataset_type: DatasetType, mode: RunMode):
        if not self.current_project:
            messagebox.showerror(
                "Error!", "Please define the project name first."
            )
            return
        filename = filedialog.askdirectory()
        if not filename:
            return
        is_sub = False
        for i, item in enumerate(os.scandir(filename)):
            if item.is_dir():
                path = item.path.replace("\\", "/")
                if self.sample_map[dataset_type][mode].size() == 0:
                    self.fetch_sample([path])
                self.sample_map[dataset_type][mode].insert(tk.END, path)
                if i > 0:
                    continue
                is_sub = True
            else:
                break
        if not is_sub:
            filename = filename.replace("\\", "/")
            if self.sample_map[dataset_type][mode].size() == 0:
                self.fetch_sample([filename])
            self.sample_map[dataset_type][mode].insert(tk.END, filename) 
Example #25
Source File: app.py    From captcha_trainer with Apache License 2.0 5 votes vote down vote up
def testing_model(self):
        filename = filedialog.askdirectory()
        if not filename:
            return
        filename = filename.replace("\\", "/")
        predict = Predict(project_name=self.current_project)
        predict.testing(image_dir=filename, limit=self.validation_batch_size) 
Example #26
Source File: easygui.py    From canari3 with GNU General Public License v3.0 5 votes vote down vote up
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.
    """
    if sys.platform == 'darwin':
        _bring_to_front()
    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
#------------------------------------------------------------------- 
Example #27
Source File: gui.py    From snn_toolbox with MIT License 5 votes vote down vote up
def set_dataset_path(self):
        """Set path to dataset."""
        p = filedialog.askdirectory(title="Set directory",
                                    initialdir=self.toolbox_root)
        self.check_dataset_path(p) 
Example #28
Source File: gui.py    From snn_toolbox with MIT License 5 votes vote down vote up
def set_cwd(self):
        """Set current working directory."""
        p = filedialog.askdirectory(title="Set directory",
                                    initialdir=self.toolbox_root)
        self.check_path(p) 
Example #29
Source File: hide_file.py    From Python-tools with MIT License 5 votes vote down vote up
def choose_directory1():
    # filename = filedialog.askopenfilename()
    filename = filedialog.askdirectory()
    if filename != '':
        l7.config(text = filename)
        b5['state'] = 'normal'
    else:
        l7.config(text = "(您没有选择任何路径)") 
Example #30
Source File: hide_file.py    From Python-tools with MIT License 5 votes vote down vote up
def choose_directory():
    # filename = filedialog.askopenfilename()
    filename = filedialog.askdirectory()
    if filename != '':
        l3.config(text = filename)
        b3['state'] = 'normal'
    else:
        l3.config(text = "(您没有选择任何文件(夹))")