title: Defining a function in a for loop
body: <p>I am new to relatively Python and tkinter. I am trying the make a button for each item that I put in the list.</p>
  
  <pre><code>from tkinter import *
  
  x = ['d', 'f']
  
  class GUI:
  
      def __init__(self, master):
  
          self.master = master
          master.title("window")
  
          self.label = Label(master, text="Window")
          self.label.grid(columnspan=5, sticky=W+E)
  
          self.close_button = Button(master, text="Close", command=master.destroy)
          self.close_button.grid(columnspan=5, sticky=W+E)
  
          for s in x:
              self.s_button = Button(master, text=s, command=self.s)
              self.s_button.grid(columnspan=5, sticky=W+E)
  
      for a in x:
          def a(self):
              print (a)     
  
  root = Tk()
  gui = GUI(root)
  root.mainloop()
  </code></pre>
  
  <p>Whenever I run the code I receive a error <code>AttributeError: 'GUI' object has no attribute 's'</code>.</p>