0
votes

I have 2 listboxes, side by side, and I'd like each to have a scrollbar. The issue I am running into is that when the listboxes are empty, they do not appear, I can only see the scrollbar.

Code below is for just one listbox. When I comment-out self.scrollbar.config and self.scrollbar.grid, I see my 20x10 listbox. When those are back in the code, as below, I only see the scrollbar. I need the listbox to remain fixed size and fill up as per the rest of my code..Screenshot: http://i.imgur.com/jQWg4d2.jpg

class Application(Frame):
  def __init__(self,  master=None):
      Frame.__init__(self, master)
      self.grid(sticky=N+S+E+W)
      self.mainframe()

  def mainframe(self):
      self.lb = Listbox(self,  width=20, height=10, bg='yellow', fg='blue')
      self.scrollbar = Scrollbar(self.lb, orient=VERTICAL)
      self.lb.config(yscrollcommand=self.scrollbar.set)
      self.scrollbar.config(command=self.lb.yview)

      self.lb.grid(row=0, column=0)

      self.scrollbar.grid(column=2)
1

1 Answers

4
votes

The problem is that you're storing the scrollbar inside the listbox, when it should be inside the frame itself.

self.scrollbar = Scrollbar(self, orient=VERTICAL)

You should also change how it's gridded, to put it in column 1 (the column immediately next to the listbox) and sticky it to the north and south:

self.scrollbar.grid(row=0, column=1, sticky=NS)

As a final note, the indentation in your post is off, but I assume it's indented further (everything under class) in your code.