title: Tkinter trying write input from file to .txt
body: <p>im trying get an input using entry and then write it to a .txt file but i get this error - <strong>Traceback (most recent call last):
    File "C:/Users/User/Desktop/Register.py", line 52, in 
    fout.write(U + '\n')
  NameError: name 'U' is not defined</strong></p>
  
  <pre><code>from Tkinter import *
  class Register:
      def __init__(self, parent):
          top = self.top = Toplevel(parent)
  
          VarEntUser = StringVar()
          VarEntPass = StringVar()
          VarEntRetype = StringVar()
  
          self.Label1 = Label(top, text = "What is your username: ")
          self.Label2 = Label(top, text = "Enter a password: ")
          self.Label3 = Label(top, text = "Retype Password: ")
          self.EntUser = Entry(top, textvariable = VarEntUser )
          self.EntPass = Entry(top, textvariable = VarEntPass)
          self.EntRetype = Entry(top, textvariable = VarEntRetype)
  
  
          self.Label1.grid(row = 0, sticky = W)
          self.Label2.grid(row = 1, sticky = W)
          self.Label3.grid(row = 2, sticky = W)
          self.EntUser.grid(row = 0, column = 1)
          self.EntPass.grid(row = 1, column = 1)
          self.EntRetype.grid(row = 2, column = 1)
  
          U = raw_input(self.VarEntUser.get())
          P = raw_input(self.VarEntPass.get())
          R = raw_input(self.VarEntRetype.get())
  
          self.MySubmitButton = Button(top, text = 'Submit', command = self.send)
          self.MySubmitButton.grid(row = 3, sticky = E)
  
  
  
  
  
      # Checks the password and checks if all fields have been entered
      def send(self):
          if len(P) &lt;= 0 and len(U) &lt;= 0:
                      print "Please fill out all fields."
  
          else:
              pass
          if P == R:
              pass
  
          else:
               print "Passwords do not match"
  
          with open('username.txt', 'a') as fout:
                   fout.write(U + '\n')
          with open('password.txt', 'a') as fout:
                   fout.write(P + '\n')
  
  
  
  
      # opens a new the registration window       
      def Register():
          inputDialog = Register(root)
          root.wait_window(inputDialog.top)
  
  root = Tk()
  
  Lable = Label(root, text = 'Choose an option')
  
  LoginB = Button(root, text = 'Log In', comman = LogIn) LoginB.pack()
  
  RegisterB = Button(root, text = 'Register', command = Register) RegisterB.pack()
  
  root.mainloop()
  </code></pre>