2

I have the following code and keep getting the error:

AttributeError: 'NoneType' object has no attribute 'curselection'

I tried changing items to simple text messages instead of items from an array, but that didn't work. So I don't know how to fix this. I think that there's some kind of issue with using grid(), because the curselection and scrollbox code examples I looked at worked - unfortunately, they didn't use grid geometry manager. Any help is much appreciated.

#############################################################################
self.test = win32print.EnumPrinters(win32print.PRINTER_ENUM_NAME, None, 2)
self.array=[]
for self.printer in self.test:
      self.array.append(self.printer["pPrinterName"])

###############################################################################
self.box = Pmw.ScrolledListBox(self.Top,
listbox_selectmode='single',
items=(self.array[1], self.array[2], self.array[3], self.array[4], self.array[5],
             self.array[6],),
label_text='Select Printer',
labelpos='nw',
listbox_height=6,
hull_width = 200,
hull_height = 200,
selectioncommand=self.selectionCommand).grid(row=12, column=0, ipadx=30, ipady=30)
    Button(self.Top, text="ok", command=self.createini).grid( row = 14, column = 0, sticky = W+E+N+S )

def selectionCommand(self):
    sels=self.box.curselection()
    if len(sels) == 0:
        print 'no selection'
    else:
        print 'Selection:', sels[0]

If there's any other method to detect what user selected from scrollbar, then that would also be a good solution.

gary
  • 4,227
  • 3
  • 31
  • 58
Thomas
  • 121
  • 2
  • 3
  • 8

1 Answers1

4
self.box = Pmw.ScrolledListBox(...).grid(row=12, column=0, ipadx=30, ipady=30)

The grid method returns None, so self.box gets set to None. Therefore you get said error when trying to call self.box.curselection. You can fix this by moving the grid call like this:

self.box = Pmw.ScrolledListBox(...)
self.box.grid(...)
Felix Loether
  • 6,010
  • 2
  • 32
  • 23