title: Pass directory name to askopenfilename
body: <p>I have three functions; with <code>dirBut</code> the user selects a directory the output of which goes into <code>dirname</code> and updates an <code>Entry</code> box. In the third function, <code>dataInput</code>, the user selects a file. I would like the open file dialog to open in the directory previously selected by the user and defined by <code>dirname</code>, however, I'm not sure how to pass <code>dirname</code> to a handle so I can use it in <code>askopenfilename</code> since <code>askdirectory</code> is called from a button.</p>
  
  <pre><code>def UserFileInput(self,status,name):
      row = self.row
      optionLabel = tk.Label(self)
      optionLabel.grid(row=row, column=0, sticky='w')
      optionLabel["text"] = name
      text = status
      var = tk.StringVar(root)
      var.set(text)
      w = tk.Entry(self, textvariable= var)
      w.grid(row=row, column=1, sticky='ew')
      self.row += 1
  
      return w, var
  
  
  def askdirectory(self):
      dirname = tkFileDialog.askdirectory()
      if dirname:
        self.directoryEntry.delete(0, tk.END)
        self.directoryEntry.insert(0, dirname)
  
  
  def askfilename(self):
    filename = tkFileDialog.askopenfilename(initialdir=dirname)
    if filename:
      self.dataInput.delete(0, tk.END)
      self.dataInput.insert(0, filename)
  
  currentDirectory = os.getcwd()
  directory,var = self.UserFileInput(currentDirectory, "Directory")
  self.directoryEntry = directory
  
  dirBut = tk.Button(self, text='Select directory...', command = self.askdirectory)
  dirBut.grid(row=self.row-1, column=2)
  
  dataInput, var = self.UserFileInput("", "Data input")
  self.dataInput = dataInput
  
  fileBut = tk.Button(self, text='Select input file...', command = self.askfilename)
  fileBut.grid(row=self.row-1, column=2)
  </code></pre>