Next / Previous / Contents / Shipman's homepage

5.9. ScrolledList.__getitem__(): Implement the Python index operator

This method is called when the user indexes a ScrolledList widget to get the text from a specific line of the listbox. The .get() method on the Listbox widget does just what we need. We raise an IndexError exception if the index is out of range.
    def __getitem__(self, k):
        """Get the (k)th line from the listbox.

        #-- 1
        if (0 <= k < self.count()):
            return self.listbox.get(k)
            raise IndexError,("ScrolledList[%d] out of range." % k)