侃侃尔雅
这是你想要的吗?import osfrom tkinter.filedialog import askdirectoryimport tkinter.messageboximport tkinter as tk# Dir selectdef selectPath(): path_ = askdirectory() path.set(path_)def create_file(): print("folder_name: ", folder.get()) print("path_name: ", path.get()) dirs = os.path.join(path.get(), folder.get()) if not os.path.exists(dirs): os.makedirs(dirs) tkinter.messagebox.showinfo('Tips:','Folder name created successfully!') else: tkinter.messagebox.showerror('Tips','The folder name exists, please change it')root = tk.Tk()root.title('Create folder')root.geometry('400x380')path = tk.StringVar() # Receiving user's file_path selectionfolder = tk.StringVar() # Receiving user's folder_name selectiontk.Label(root,text = "Target path:").place(x=50, y= 250)tk.Entry(root, textvariable = path).place(x=110, y= 250)tk.Button(root, text = "Path select: ", command = selectPath).place(x=265, y= 250)tk.Label(root,text = "Folder name:").place(x=50, y= 300)tk.Entry(root,textvariable = folder).place(x=110, y= 300)tk.Button(root, text = "Submit: ", command = create_file).place(x=265, y= 300)root.mainloop()path和folder变量是选择的路径和用户创建的文件夹名称。它在我的电脑上看起来像这样: