python——利用UI选择路径
python利用UI选择路径
import tkinter as tk from tkinter.filedialog import askdirectory def selectPath(): path_ = askdirectory() path.set(path_) root = tk.Tk() path = tk.StringVar() tk.Label(root,text = "目标路径:").grid(row = 0, column = 0) tk.Entry(root, textvariable = path).grid(row = 0, column = 1) tk.Button(root, text = "路径选择", command = selectPath).grid(row = 0, column = 2) root.mainloop()