title: How to fix "free variable 'db_username' referenced before assignment in enclosing scope"
body: <p>ive just started learning python and im great at making programs without GUI's but ive been working with them and without tkinter my pymysql code works just fine but when i started playing with tkinter it wasnt working like it did without it i keep getting referenced before assignment no matter how many different formats\organizations ive tried it still wont work heres the full code " <a href="https://pastebin.com/04uFWB1R" rel="nofollow noreferrer">https://pastebin.com/04uFWB1R</a> "</p>
  
  <p>like i said it works just fine without a gui but as soon as i try it with a gui it wont work</p>
  
  <pre><code>def lClick():
      __uID = uID.get()
      __uName = uName.get()
      __passW = passW.get()
      print(__uName)
      print(__passW)
      auth = Label(lWindow, text="Authorizing...",font=("Areial Bold", 10))
      auth.place(x=-10,y=99)
      time.sleep(0.5)
      time.sleep(1)
      def authorize():
          if __uID == "01":
              auth.configure(text='''
              User Authenticated...
              Accessing Database
              ''')
          ##############################################################
              def dbCon():
                  con = pymysql.connect(host='192.***.***.**',
                      user='****',
                      password='******',
                      db='python1',
                      charset='utf8mb4',
                      cursorclass=pymysql.cursors.DictCursor)
                  with con:
                      cur = con.cursor()
                      cur.execute("SELECT * FROM users WHERE 'id' = '{0}'".format(__uID))
                      rows = cur.fetchall()
                      for row in rows:
                          db_username = row['username']
                          db_password = row['password']
                  def logon():
                      if __uName == db_username:
                          auth.configure(text="DataBase Connected")
                      else:
                          auth.configure(text="Error Has Occured")
                  logon()
              dbCon()
          else:
              auth.configure(text="Not Authorized")
      authorize()
  </code></pre>
  
  <p>im trying to figure out how to fix the "variable referenced before assignment" error</p>