title: Receiving a python TypeError: expected str, bytes or os.PathLike object, not StringVar
body: <p>I am trying to create a set of tkinter buttons for a python script that reads a text file containing a list of filenames, then searchs for those names in a directory selected by the user and copies any found files to another location stipulated by the user.</p>
  <p>But i am receiving this error now that i have inserted buttons</p>
  <pre><code>
      with open(filePath, &quot;r&quot;) as fh:
  TypeError: expected str, bytes or os.PathLike object, not StringVar
  
  </code></pre>
  <p>Here's the code below:</p>
  <pre><code>import os
  import shutil
  from tkinter import filedialog
  from tkinter import *
  
  def browse_button():
      filePath = filedialog.askopenfilename()
      
  def browse_button():
      global folder_path
      folderPath = filedialog.askdirectory()
  
  def browse_button():
      global destination
      destination = filedialog.askdirectory()
  
  root = Tk()
  
  filePath = StringVar()
  lbl1 = Label(master=root,textvariable=filePath)
  lbl1.grid(row=0, column=1)
  button2 = Button(text=&quot;Browse Text File&quot;, command=browse_button)
  button2.grid(row=0, column=3)
  
  
  folderPath = StringVar()
  lbl1 = Label(master=root,textvariable=folderPath)
  lbl1.grid(row=0, column=1)
  button2 = Button(text=&quot;Browse Source Folder&quot;, command=browse_button)
  button2.grid(row=0, column=6)
  
  
  destination = StringVar()
  lbl1 = Label(master=root,textvariable=destination)
  lbl1.grid(row=0, column=1)
  button2 = Button(text=&quot;Browse Destination Folder&quot;, command=browse_button)
  button2.grid(row=0, column=9)
   
  filesToFind = []
  with open(filePath, &quot;r&quot;) as fh:
      for row in fh:
          filesToFind.append(row.strip())
  
  
  for filename in os.listdir(folderPath):
      if filename in filesToFind:
          filename = os.path.join(folderPath, filename)
          shutil.copy(filename, destination)
  
  mainloop()
  
  </code></pre>
  <p>BELOW IS THE UPDATED CODE:</p>
  <pre><code>
  import os
  import shutil
  from tkinter import filedialog
  from tkinter import *
  
  def browse_button_1():
      global filePath
      filePath = filedialog.askopenfilename()
  
  def browse_button_2():
      global folder_path
      folderPath = filedialog.askdirectory()
  
  def browse_button_3():
      global destination
      destination = filedialog.askdirectory()
  
  def browse_button_4():
      global run
      run = runScript()
  
  root = Tk()
  
  def runScript():
  
      filesToFind = []
      with open(filePath.get(), &quot;r&quot;) as fh:
          for row in fh:
              filesToFind.append(row.strip())
  
      for filename in os.listdir(folderPath.get()):
          if filename in filesToFind:
              filename = os.path.join(folderPath.get(), filename)
              shutil.copy(filename, destination.get())
  
  filePath = StringVar()
  lbl1 = Label(master=root,textvariable=filePath)
  lbl1.grid(row=0, column=1)
  button2 = Button(text=&quot;Browse Text File&quot;, command=browse_button_1)
  button2.grid(row=0, column=3)
  
  
  folderPath = StringVar()
  lbl1 = Label(master=root,textvariable=folderPath)
  lbl1.grid(row=0, column=1)
  button3 = Button(text=&quot;Browse Source Folder&quot;, command=browse_button_2)
  button3.grid(row=0, column=6)
  
  
  destination = StringVar()
  lbl1 = Label(master=root,textvariable=destination)
  lbl1.grid(row=0, column=1)
  button4 = Button(text=&quot;Browse Destination Folder&quot;, command=browse_button_3)
  button4.grid(row=0, column=9)
  
  
  run = StringVar()
  lbl1 = Label(master=root,textvariable=run)
  lbl1.grid(row=0, column=1)
  button5 = Button(text=&quot;Run Script&quot;, command=runScript)
  button5.grid(row=0, column=12)
  
  mainloop()
  
  
  </code></pre>
  <p>The is the updated codes error:</p>
  <p>Slightly different issue, I am recieving this error:</p>
  <pre><code>
  Exception in Tkinter callback
  Traceback (most recent call last):
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py&quot;, line 1705, in __call__
      return self.func(*args)
    File &quot;/Users/********/Documents/test.py&quot;, line 30, in runScript
      with open(filePath.get(), &quot;r&quot;) as fh:
  AttributeError: 'str' object has no attribute 'get'
  
  </code></pre>