title: Updating tkinter label
body: <p>I am trying to update a label, but the code I have written creates a new label each time. I am relatively new to tkinter so I couldn't understand how to apply other answers to my code.  </p>
  
  <pre><code>from tkinter import *
  import random
  
  class Window(Frame):
  
      def __init__(self, master=None):
          Frame.__init__(self, master) 
          self.master=master 
          self.init_window()
  
      def init_window(self): 
          self.pack(fill=BOTH, expand=1)
          testButton=Button(self, text="Press", command=calc)
          testButton.pack()
          l1=Label(text="")
  
      def testbutton(ans): #creates a new instance of l1 each time, I want to update existing l1
          var=StringVar()
          l1=Label(textvariable=var) #l1.configure() gives error l1 not defined
          var.set(ans)
          l1.pack()
  
  def calc():
      list1=["a","b","c"]
      index=random.randint(0,2)
      answer=list1[index]
      Window.testbutton(answer)
  
  root=Tk()
  root.geometry("400x300")
  app=Window(root)
  root.mainloop()
  </code></pre>
  
  <p>Each time the button is pressed, a new label is created, instead of updating the text on the existing label. 
  This is a simplified version of my actual project, but highlights the issue with labels. 
  I've tried to use <code>l1.configure(...)</code> inside the testbutton function but then it runs an error that l1 isn't defined.</p>