codefail
codefail

Reputation: 381

Python Tkinter - multiple listboxes and scrollbars

having issues with getting the scrollbars set correctly. The following code renders 2 listboxes, one on top of the other, and 2 scrollbars. However, scrollbar spans the entire height of both boxes, and scrollbar2 is only the 2nd listbox (lb2). I need scrollbar and lb to be the same height, and scrollbar2 and lb2 to be the same height. Here is a screenshot of what I currently have http://tinyurl.com/mxo9llb

frame = Frame(app,bd=2,relief=SUNKEN)

scrollbar = Scrollbar(frame, orient="vertical")
lb = Listbox(frame, width=30, height=10, yscrollcommand=scrollbar.set)
scrollbar.config(command=lb.yview)

scrollbar.pack(side="right", fill="y")
lb.pack(side="top",fill="both", expand=True)


scrollbar2 = Scrollbar(frame, orient="vertical")
lb2 = Listbox(frame, width=30, height=10, yscrollcommand=scrollbar2.set)
scrollbar2.config(command=lb2.yview)

scrollbar2.pack(side="right",fill="y")
lb2.pack(side="top",fill="both", expand=True)

for item in ad_members:
    lb.insert(END, item)

for item in ad_members:
    lb2.insert(END, item)

frame.pack(side='right',padx=15)

Upvotes: 0

Views: 1246

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

For such a layout, you're better off using grid rather than pack. You can't do what you want using pack unless you add some extra frames to help with the layout.

Using pack, you need to create two additional frames: one for the top half and one for the bottom half. Then, within the frame you can put each scrollbar on the right and the listbox on the left. Finally, pack the frames on top of each other.

Using grid, you would put each listbox/scrollbar pair on a different row, with the listbox in column zero and the scrollbar in column one.

Upvotes: 1

Related Questions