title: Variable referenced before assignment - Python
body: <p>I am getting the error...</p>
  
  <pre><code>a = a + b
  UnboundLocalError: local variable 'a' referenced before assignment
  </code></pre>
  
  <p>I don't understand why the error occurs if I have assigned the two variables a and b at the start.</p>
  
  <pre><code>from tkinter import *
  
  a = 10
  b = 12
  def stopProg(e):
      root.destroy()
  
  def addNumbers(e):
      a = a + b
      label1.configure(text= str(a))
  
  root=Tk()
  button1=Button(root,text="Exit")
  button1.pack()
  button1.bind('&lt;Button-1&gt;',stopProg)
  button2=Button(root,text="Add numbers")
  button2.pack()
  button2.bind('&lt;Button-1&gt;',addNumbers)
  label1=Label(root,text="Amount")
  label1.pack()
  
  root.mainloop()
  </code></pre>