title: Checkbuttons and buttons: using lambda
body: <p>I am trying to make a number of checkboxes based on a list, however it looks as if I am screwing up the <em>command call</em> and <em>variable aspect</em> of the button.  </p>
  
  <p>My code is:</p>
  
  <pre><code>class Example(Frame):
  
  def __init__(self, parent):
      Frame.__init__(self, parent)
  
      self.parent = parent
      self.initUI()
  
  def initUI(self):
  
      self.courses = ["CSE 4444", "CSE 4343"]
      self.vars = []
  
      self.parent.title("Homework Helper")
  
      self.course_buttons()
  
      self.pack(fill=BOTH, expand=1)
  
  def course_buttons(self):
      x = 0
      y = 0
  
      for i in range(0, len(self.courses)):
          self.vars.append(IntVar())
          cb = Checkbutton(self, text=self.courses[i],
                           variable=self.vars[i],
                           command=lambda: self.onClick(i))
          cb.select()
          cb.grid(column=x, row=y)
          y = y+1
  
  def onClick(self, place):
  
      print place
      if self.vars[place].get() == 1:
          print self.courses[place]
  </code></pre>
  
  <p>The test so far is for the course to be printed on the console when the check box is on, however it only works for the second button, button "CSE 4343".  When I interact with button "CSE 4444", nothing is printed.</p>
  
  <p>Also, the "place" value is onClick is always 1, whether I am clicking button "CSE 4343" or button "CSE 4444".</p>