title: os.rename() creates new file instead of renaming file
body: <p>So, I'm using tkinter with python 3 and windows 10 (64 bit). I have a save function, that saves what's written in several entry boxes as a .txt file. The user can then open the .txt files from the application, and all of the data will go back to its original position. As part of my program, a label displays the file name of the currently open file. The user can edit the filename from within the window.</p>
  
  <p>When the user saves, I want to change the filename of the file to what the user has written in the window. This works for the most part. However, if the user has written anything in the entry box, and changes the filename within my application, when they save it doesn't just change the actual filename.</p>
  
  <p>Instead, it just creates a new file with the name of the new filename. It also spits the error:</p>
  
  <pre><code>FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:/Users/User/Documents/Python stuff/Other apps/Veteris/Scripts/test.txt' -&gt; 'test2.txt'
  
  </code></pre>
  
  <p>I'm using the os.rename() function. Also, when the user opens a file, I can't get the filename to display. Any help on that would also be appreciated. Here is my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>def _open():
      global file_dir
  
      file_dir = tkfd.askopenfilename(title = "Open...", defaultextension = 
                     '.txt', filetypes = (('Text files', '*.txt'), ('Excel 
                      Workbook', '*.xlsx')))
  
      if file_dir.endswith('.txt'):
          with open(file_dir, 'r') as input_file:
                      # saves stuff
  
      elif file_dir.endswith('.xlsx'):
             # saves stuff
  
      new_file_name = os.path.basename(file_dir.name).strip('.txt.xlsx')
  
      file_title.config(text = new_file_name)
  
  def save_as():
      global filepath
      global file_dir
      global file_name
      global save_status
  
  
      file_dir = tkfd.asksaveasfilename(initialfile = file_name, initialdir 
                   = filepath, title = "Save as", defaultextension = '.txt', 
                   filetypes = [('Text files', '*.txt')]) # Sets file_dir to the 
                    directory the user creates (in save as dialog)
  
      try:
          with open(file_dir, 'w') as output_file:
                  # saves the stuff
  
  
          time_saved_label.config(text = "Saved")
          save_status = True
  
      except:
          print("'Save as' cancelled")
  
  def save():
      global file_dir
      global file_name
      global save_status
  
      notepad_save = notepad.get('1.0', END).strip('\n')
  
      eyes_save = eyes_entry.get().strip('\n') + '\n'
      if file_dir is None:
          return save_as()
  
      else: 
          with open(file_dir, 'w') as output_file:
  
  
              output_file.write(notepad_save)
  
          new_file_name = file_name + '.txt'
          os.rename(file_dir, new_file_name)
  
  </code></pre>
  
  <p>Like I said, the code should change the name of the file and that's it (along with updating the contents).</p>
  
  <p>Instead, it just creates a copy with the most recent changes.</p>