Aayush Shukla
Aayush Shukla

Reputation: 58

Why isn't Listbox covering whole Frame in Tkinter?

I'm creating a simple GUI with Python Tkinter, and using Frame as containers. When I added a Listbox inside the Frame, it only occupies a small space in the Frame, rest space remains empty. I want it to cover whole Frame. Here's the code, and the output as image:

from tkinter import *

root = Tk()
root.geometry('1280x720')
root.title("Music Player")
root.grid_rowconfigure((0,1,2,3,4,5), weight=1)
root.grid_columnconfigure((0,), weight=1)
root.grid_columnconfigure((1,), weight=5)
root.resizable(False, False)

listframel = Frame(root, highlightbackground="black", highlightthickness=5)
listframel.grid(row=0, column=0, sticky=NSEW, rowspan=5)
listframer = Frame(root, highlightbackground="black", highlightthickness=5)
listframer.grid(row=0, column=1, sticky=NSEW, rowspan=5)

listbox = Listbox(listframel)
listbox.grid(row=0, column=0, rowspan=5, sticky=NSEW)
lst = list(x for x in range(100))
for i in range(len(lst)):
    listbox.insert(i+1, lst[i]+1)

root.mainloop()

Output

Upvotes: 0

Views: 286

Answers (1)

Derek
Derek

Reputation: 2234

You need to apply grid_rowconfigure and grid_columnconfigure to all containers (root, listframel and listframer).

Upvotes: 1

Related Questions