title: Saving a variable in a text file
body: <p>I would like to save variable (including its values) into a text file, so that the next time my program is opened, any changes will be automatically saved into the text file
  .For example:</p>
  
  <pre><code>    balance = total_savings - total_expenses 
  </code></pre>
  
  <p>How would I go about saving the variable itself into a text file instead of only its value?
  This section is for the register page</p>
  
  <pre><code>    from tkinter import *
      register = Tk()
      Label(register, text ="Username").grid(row = 0)
      Label(register, text ="Password").grid(row = 1)
  
      e1 = Entry (register)
      e2 = Entry (register, show= "*")
  
      e1.grid(row = 0, column = 1)
      e2.grid(row = 1, column = 1)
  
      username = e1.get()
      password = e2.get()
  
  
      button1 = Button(register, text = "Register", command = register.quit)
      button1.grid(columnspan = 2)
      button1.bind("&lt;Button-1&gt;")
  
      import json as serializer
      with open('godhelpme.txt', 'w') as f:
          serializer.dump(username, f)
      with open('some_file.txt', 'w') as f:
          serializer.dump(password, f)
  
  
      register.mainloop()
  </code></pre>
  
  <p>Altered code:</p>
  
  <pre><code>    from tkinter import *
      register = Tk()
      Label(register, text ="Username").grid(row = 0)
      Label(register, text ="Password").grid(row = 1)
  
      username = StringVar()
      password = StringVar()
  
      e1 = Entry (register, textvariable=username)
      e2 = Entry (register, textvariable=password, show= "*")
  
      e1.grid(row = 0, column = 1)
      e2.grid(row = 1, column = 1)
  
  
      button1 = Button(register, text = "Register", command = register.quit)
      button1.grid(columnspan = 2)
      button1.bind("&lt;Button-1&gt;")
  
      import json as serializer
      with open('godhelpme.txt', 'w') as f:
          serializer.dump(username.get(), f)
      with open('some_file.txt', 'w') as f:
          serializer.dump(password.get(), f)
  </code></pre>
  
  <p>Log in code:</p>
  
  <pre><code>    from tkinter import *
      login = Tk()
      Label(login, text ="Username").grid(row = 0)
      Label(login, text ="Password").grid(row = 1)
  
      username = StringVar()
      password = StringVar()
  
      i1 = Entry(login, textvariable=username)
      i2 = Entry(login, textvariable=password, show = "*")
  
      i1.grid(row = 0, column = 1)
      i2.grid(row = 1, column = 1)
  
      def clickLogin():
              import json as serializer
              f = open('godhelpme.txt', 'r')
              file = open('some_file.txt', 'r')
              if username == serializer.load(f):
                      print ("hi")
              else:
                      print ("invalid username")
                      if password == serializer.load(file):
                              print ("HELLOOOO")
                      else:
                              print ("invalid password")
  
  
  
      button2 = Button(login, text = "Log In", command = clickLogin)
      button2.grid(columnspan = 2)
  
  
      login.mainloop()
  </code></pre>