0

I read through a bunch of tkinter questions that were asked here and haven't been able to figure out how to get the scrollbar to show up. Any help would be much appreicated.

    self.resultsCanvas = Canvas(self, bg='white', height=300, width=300, relief=FLAT).grid(column=0, row=8)
    self.resultsCanvas.config(yscrollcommand = self.scrollResults.set)
    self.scrollResults = Scrollbar(root, command=self.resultsCanvas.yview).grid(column=11, row=8, sticky='E')
    self.blankSpace03 = Label(self, text="  ").grid(column=1, row=9)

I get the following error message:

self.resultsCanvas.config(yscrollcommand = self.scrollResults.set)
AttributeError: 'NoneType' object has no attribute 'config'
jimsta
  • 11
  • 3

1 Answers1

0

You can't initialize and layout a Widget on the same line if you want to keep the reference. You have to put those on separate lines:

self.resultsCanvas = Canvas(self, bg='white', height=300, width=300, relief=FLAT)
self.resultsCanvas.grid(column=0, row=8)
self.scrollResults = Scrollbar(root, command=self.resultsCanvas.yview)
self.scrollResults.grid(column=11, row=8, sticky='E')
self.resultsCanvas.config(yscrollcommand = self.scrollResults.set)

It's good to always use separate lines to avoid this kind of bug in the future.

Novel
  • 13,406
  • 2
  • 25
  • 41
  • Thanks Novel, I broke out the lines but now I'm getting a different error: self.resultsCanvas.config(yscrollcommand = self.scrollResults.set) AttributeError: 'MainApp' object has no attribute 'scrollResults' – jimsta Dec 21 '17 at 19:49
  • Yes, you need to define the scrollResults before you use it. I updated my answer. – Novel Dec 21 '17 at 20:03
  • Oh man, I feel dumb. So it was a matter of ordering the yscrollcommand after defining the scrollbar widget. Thank you so much, just starting to learn python and this helped a great deal! Now I have to figure out how to make the scroll bar appear next to and not below the canvas :D – jimsta Dec 21 '17 at 20:49