0

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.

What I have is:

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()

However, clicking any button results in only the last text from the last contact button created being displayed. A similar issue appeared already, and although he says he solved his issue, I can't seem to understand how or why.

I tried adapting his code to fit mine but I get an error saying Nonetype has no listofTexts attribute.

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()

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.

Thank you

edit: I don't see how Checkboxes 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.

edit2: That solution didn't work, its still giving findContant a noneType for the name string.

Community
  • 1
  • 1
Tryer
  • 120
  • 1
  • 7
  • @TigerhawkT3 Not a duplicate, one deals with courses, the other with text messages. And either way I'm still confused. – Tryer May 09 '15 at 00:18

1 Answers1

1

I've fixed it and here's how.

def displayTexts(name, list_of_Contacts): 

takes in a string representing the name, and the listOfContacts. Meanwhile:

...command= lambda a=k.name: displayTexts(buttons[a], list_of_Contacts))

wasn't passing in a string for the name, it was passing in the button. It was fixed by making it:

...command= lambda a=k.name: displayTexts(a, list_of_Contacts))
Prashant Sengar
  • 506
  • 1
  • 7
  • 24
Tryer
  • 120
  • 1
  • 7