title: Tkinter: making an arbitrary amount of buttons and getting their fields
body: <p>I am trying to make a gui application in Python using tKinter to display an arbitrary amount of phone numbers in buttons, and for clicking that button to display that contact's text messages.</p>
  
  <p>What I have is:</p>
  
  <pre><code>from tkinter import *
  
  def displayTexts(name, list_of_Contacts):
      cont = findContact(name, list_of_Contacts)
      for text in cont.listOfTexts:
          (Message(right_frame, text=text.body)).pack(side=TOP)
  
  for contact in list_of_Contacts:
      (Button(left_frame, text=contact.name, command= lambda: displayTexts(contact.name, list_of_Contacts))).pack()
  </code></pre>
  
  <p>However, clicking any button results in only the last text from the last contact button created being displayed. A similar <a href="https://stackoverflow.com/questions/21990685/tkinter-creating-an-arbitrary-number-of-buttons-widgets">issue</a> appeared already, and although he says he solved his issue, I can't seem to understand how or why.</p>
  
  <p>I tried adapting his code to fit mine but I get an error saying Nonetype has no listofTexts attribute. </p>
  
  <pre><code>buttons = dict()
  for k in list_of_Contacts:
      buttons[k.name] = Button(left_frame, text=k.name, command= lambda a=k.name: displayTexts(buttons[a], list_of_Contacts)).pack()
  </code></pre>
  
  <p>One thing I can't figure out is how to get the text of the button from button[a], and another is how this list/dictionary solution is supposed to be implemented.</p>
  
  <p>Thank you</p>
  
  <p>edit: I don't see how <a href="https://stackoverflow.com/questions/29837203/tkinter-checkboxes">Checkboxes</a> is a duplicate, in fact I don't understand his problem either. The answer sounds like it could apply here but I haven't the faintest how.</p>
  
  <p>edit2: That solution didn't work, its still giving findContant a noneType for the name string.</p>