title: Clear text from tkinter entry widget
body: <p>I am using Tkinter entry widgets to allow users to input text to a GUI. The entry widgets have default text which I would like to clear with a single button press. I have the following code:</p>
  
  <pre><code>from Tkinter import *
  
  def delete_entries(fields):
    for field in fields:
      field.delete(0,END)
  
  def UserInput(status,name):
    optionFrame = Frame(root)
    optionLabel = Label(optionFrame)
    optionLabel["text"] = name
    optionLabel.pack(side=LEFT)
    var = StringVar(root)
    var.set(status)
    w = Entry(optionFrame, textvariable= var)
    w.pack(side = LEFT)
    optionFrame.pack()
  
  if __name__ == '__main__':
    root = Tk()
    fields = 'ExperimentNumber', 'OutputFileName', 'npts1', 'block1'    
    ExperimentNumber = UserInput("1", "Experiment number")
    OutputFileName = UserInput("output.txt", "Output file name")
    npts1 = UserInput("1000", "Number of points")
    block1 = UserInput("8", "Block size")
  
    Delete_button = Button(root, text = 'Clear all', command = delete_entries(fields))
    Delete_button.pack()
  </code></pre>
  
  <p>I have tried creating <code>fields</code> with the list of variables that I want to delete (as above) and iterating over this in the function <code>delete_entries()</code>, however this returns an error because the entries in fields are strings. I have tried replacing fields with <code>fields = ExperimentNumber</code> for example, but this returns an error because ExperimentNumber hasn't yet been defined. Finally I tried putting <code>ExperimentNumber</code> within the delete function i.e.</p>
  
  <pre><code>def delete_entries():
        ExperimentNumber.delete(0,End)
  </code></pre>
  
  <p>but this doesn't work because <code>ExperimentNumber</code> has the attribute <code>NoneType</code> (I don't understand why this is, because the <code>delete_entries()</code> function isn't called until after the <code>ExperimentNumber</code> Entry widget is created via the function <code>UserInput</code>). How can I go about deleting all the text in the Entry widgets? I have about 20 of these in my actual code and would like the user to be able to clear all the fields with one button press.</p>