title: Execute function when button is pressed, not when script runs
body: <p>I have come up with this code:</p>
  
  <pre><code>import tkinter
  from tkinter.filedialog import askopenfilename
  
  def browse():
      inputfilename=askopenfilename()
      return inputfilename
  
  def fileManipulator(infile=browse(),outfile="C:\\out\\File.kml"):
      #code that manipulates the file here
      file.save(outfile)
  
  root=tkinter.Tk()
  browseButton=tkinter.Button(root,text="Browse",command=browse)
  browseButton.pack()
  fileButton=tkinter.Button(root,text="Manipulate file",command=fileManipulator)
  fileButton.pack()
  root.mainloop()
  </code></pre>
  
  <p>The code gives me a GUI with two buttons. The <em>Browse</em> button is supposed to let the user browse through the input file. The <em>Manipulate File</em> button is supposed to process that file and save the file output somewhere.</p>
  
  <p>The problem I am facing is that the browse <code>askopenfilename</code> function is executing as soon as I run the script.That happens because I am calling the function inside the definition of the fileManipulator function. The reason I am calling the function inside fileManipulator is obviously because I want to use the path that askopenfilename returns as input file.</p>
  
  <p>Is there a workaround to not execute the <code>askopenfilename</code> immediately, but when the <em>Browse</em> button is pressed?</p>
  
  <p><strong>EDITS:</strong> I also don't want the browse() function to be executed again when I press the <em>File Manipulator</em> button.</p>