path.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:tfc 作者: maqp 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号