Question

self.__tracksListBox = Listbox(self.__master, width=100, height=25).grid(row=0, column=1,
                                                                           rowspan=4)

I'm trying to display options in a Listbox, but the following error is thrown:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)
  File "C:\Users\aawiesinger5000\Desktop\CS 110 Final Project\layoutGUI.py", line 213, in showTracks
    self.__tracksListBox.insert(END, titleStr)
AttributeError: 'NoneType' object has no attribute 'insert'

when I try to use the list box like this:

if tracks:
            titleStr = ""
            for track in tracks:
                titleStr += track + "\n"
            self.__tracksListBox.insert(END, titleStr)

Does anyone know why?

Thank you!!

Was it helpful?

Solution

grid method does not return; implicitly return None.

Separate the following statement into two statements:

self.__tracksListBox = Listbox(self.__master, width=100, height=25).grid(row=0, column=1,
                                                                           rowspan=4)

like:

self.__tracksListBox = Listbox(self.__master, width=100, height=25)
self.__tracksListBox.grid(row=0, column=1, rowspan=4)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top