title: How to write a file to a user generated path
body: <p>I have a GUI where I ask the user to select the directory and create a folder. Then it has the user browse for a file. That file is then read and directed to an absolute file path. I would, instead, like that path to be the user selected path and folder and cannot figure that out! Please help. _/_</p>
  <pre><code>from tkinter import *
  from tkinter import ttk, filedialog
  from tkinter.filedialog import askopenfile
  import os
  import pandas as pd
  
  def selectPath():   
      path_ = askdirectory()
      path.set(path_)
  def create_subfolder():  
      print(&quot;folder_name: &quot;, folder.get())
      print(&quot;path_name: &quot;, 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')
  
  path = tk.StringVar()   # Receiving user's file_path selection
  folder = tk.StringVar() # Receiving user's folder_name selection        
  
  
  tk.Entry(window,textvariable = path).place(relx=0.05, rely=0.12, relheight=0.06, relwidth=0.30)
  tk.Button(window, text = &quot;Select your directory: &quot;, command = selectPath).place(relx=0.37, rely=0.11, relheight=0.08, relwidth=0.30)
  
  tk.Entry(window,textvariable = folder).place(relx=0.05, rely=0.20, relheight=0.06, relwidth=0.30)
  tk.Button(window, text = &quot;Submit Folder Name: &quot;, command = create_subfolder).place(relx=0.37, rely=0.19, relheight=0.08, relwidth=0.30)
  
  def openFile():
      filename = filedialog.askopenfilename(initialdir = r'C:\ABC\123\MyFile',
                                            filetypes=[(&quot;Excel Files&quot;, &quot;*.xlsx&quot;)])
      os.startfile(filename)
      df = pd.read_excel(filename, sheet_name = 'Order Details')
    
      df.to_excel(r'C:\ABC\123\MyFile_2.xlsx')
  </code></pre>
  <p>can this be df.to_excel(dirs)?</p>
  <pre><code>    
  def onClick():
      tk.messagebox.showinfo(&quot;Importing My File&quot;,  &quot;Your file imported!&quot;)
      
  button = tk.Button(canvas, text='Import Intelliscan File', bg='LightYellow2', fg='black',command=openFile)
  button.place(relx=0.05, rely=0.29, relheight=0.13, relwidth=0.30)  
  
  window.mainloop()```
  
  Thanks in advance!
  </code></pre>