python TK 选择文件、文件夹
导包
import tkinter as tk
from tkinter import filedialog
正式代码
def get_item_path():
'''打开选择文件夹对话框'''
root = tk.Tk()
root.withdraw()
Folderpath = filedialog.askdirectory() # 文件夹路径
# Filepath = filedialog.askopenfilename() #文件文件路径
return Folderpath
if __name__ == '__main__':
get_item_path()