title: Easygui file encoding and returning to the begin of the code
body: <p>So i made an application that can login, make user, chance username and change passwords.
  The first problem is that i cant get file encoding to work. it saves the password in plain text (in psw.txt, but i want it to save to psw.txt encoded).
  The 2nd problem is, when the if loops are done, it doesnt go back to the main choice buttonbox.</p>
  <p>Any advice would be appriciated, thank you.</p>
  <pre><code>from easygui import *
  
  msg = &quot;make a choice&quot;
  title = &quot;test&quot;
  choices = [&quot;login&quot;, &quot;make user&quot;, &quot;change username&quot;, &quot;change password&quot;, &quot;cancel&quot;]  #buttonbox waarin je een aantal keuzes in kunt maken
  reply = buttonbox(msg, title, choices=choices )
  
  if reply == &quot;make user&quot;:     # als de knop voor make user word gedrukt dan gaat deze make user multpasswordbox
    msg = &quot;What are the User ID and Password you want to use&quot;
    title = &quot;Making an User&quot;
    fieldNames = [&quot;User ID&quot;, &quot;Password&quot;] #de 2 veldnamen die gebruikt worden
    fieldValues = []  # we start with blanks for the values
    fieldValues = multpasswordbox(msg,title, fieldNames)
    usr = open(&quot;usr.txt&quot;, &quot;w&quot;)  #opent usr en psw.txt in write mode
    psw = open(&quot;psw.txt&quot;, &quot;w&quot;, encoding='utf8')
    psw.write(str(fieldValues[1]))   #schrijft de usename in usr.txt
    usr.write(str(fieldValues[0]))  #schrijft de password in psw.txt
    psw.close()
    usr.close()
    print(fieldValues[0])     #testen om te kijken of de username en password ook opgeslagen word
    print(fieldValues[1])
  
    while 1:                                     #while loop die kijkt of de velden niet leeg worden gelaten
      errmsg = &quot;&quot;
      for i in range(len(fieldNames)):
        if fieldValues[i].strip() == &quot;&quot;:
          errmsg = errmsg + ('&quot;%s&quot; is a required field.\n\n' % fieldNames[i])
      if errmsg == &quot;&quot;: break # no problems found
      fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
  
  
  
  if reply == &quot;login&quot;:    # als de knop voor login word gedrukt dan krijg je een multpasswordbox waarmee je kunt inloggen
    msg = &quot;Enter logon information&quot;
    title = &quot;Login&quot;
    fieldNames = [&quot;User ID&quot;, &quot;Password&quot;]
    fieldValues = []  # we start with blanks for the values
    fieldValues = multpasswordbox(msg,title, fieldNames)
    psw = open(&quot;psw.txt&quot;, &quot;r&quot;)        #opent de psw en usr.txt in leesmodus
    usr = open(&quot;usr.txt&quot;, &quot;r&quot;)
    password = psw.read()             #leest het bestand uit en slaat het op onder &quot;username&quot; en &quot;password&quot;
    username = usr.read()
    print(fieldValues[1])             #test om te kijken of de waardes kloppen
    print(username)
    if fieldValues[0] != username and fieldValues[1] != password:             #kijkt of de username/password combinatie correct is
      msgbox(&quot;username and password is wrong&quot;)
      
    elif fieldValues[0] != username and fieldValues[1] == password:
      msgbox(&quot;Username is wrong&quot;)
      
    elif fieldValues[0] == username and fieldValues[1] != password:
      msgbox(&quot;Password is wrong&quot;)
    elif fieldValues[0] == username and fieldValues[1] == password:
      msgbox(&quot;You are logged in&quot;)
    
    psw.close()
    usr.close()
    
  if reply == &quot;change username&quot;:   #hier word de username veranderd
    msg = &quot;enter old username and new username&quot;
    title = &quot;Change username&quot;
    fieldNames = [&quot;Old User ID&quot;, &quot;New User ID&quot;]
    fieldValues = []  # we start with blanks for the values
    fieldValues = multpasswordbox(msg,title, fieldNames)
    
    usr = open(&quot;usr.txt&quot;, &quot;r&quot;)   #opent usr.txt in leesmodus
  
    username = usr.read() #leest het bestand uit en slaat het op onder &quot;username&quot;
  
    if fieldValues[0] != username:
      msgbox(&quot;Username is wrong&quot;)
      usr.close()
      
    elif fieldValues[0] == username:
      usr = open(&quot;usr.txt&quot;, &quot;w&quot;)   #opent usr.txt in schrijfmodus
      usr.write(str(fieldValues[1])) #vervangt de username
      print(username)
      usr.close()
  
  if reply == &quot;change password&quot;:   #hier word de wachtwoord veranderd
    msg = &quot;enter old password and new password&quot;
    title = &quot;Change password&quot;
    fieldNames = [&quot;Old password&quot;, &quot;New password&quot;]
    fieldValues = []  # we start with blanks for the values
    fieldValues = multpasswordbox(msg,title, fieldNames)
    psw = open(&quot;psw.txt&quot;, &quot;r&quot;)   #opent psw.txt in leesmodus
    password = psw.read() #leest het bestand uit en slaat het op onder &quot;username&quot;
  
    if fieldValues[0] != password:
      msgbox(&quot;password is wrong&quot;)
      psw.close()
      
    elif fieldValues[0] == password:
      psw = open(&quot;psw.txt&quot;, &quot;w&quot;,encoding='utf8')   #opent psw.txt in schrijfmodus
      psw.write(str(fieldValues[1])) #vervangt de password
      msgbox(&quot;password is changed&quot;)
      psw.close()
   
  </code></pre>