1

I am trying to create a product list using a grid view in Tkinter, but I am totally confused about that why the scrollbar thing is not working, I have checked so many tutorials to fix the scrollbar.

first of all, I thought it was because of pack() or grid(), but after using pack() instead of grid things become worse,

please help me solve this issue

frame_main = Frame(root, bg="gray")
frame_main.pack(fill='both', expand=1)

my_canvas = Canvas(frame_main, bg="red")
my_canvas.pack(fill=Y, expand=1)

vsb = Scrollbar(frame_main, orient="vertical", command=my_canvas.yview)
vsb.pack(side='right', fill=Y)

my_canvas.configure(yscrollcommand=vsb.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(
    scrollregion=my_canvas.bbox("all")))

inner_frame = Frame(my_canvas).pack(fill=Y, expand=1)

my_canvas.create_window((0, 0), window=inner_frame, anchor="nw")

img = ImageTk.PhotoImage(Image.open(
    'images/apple--600.png').resize((200, 200), Image.ANTIALIAS))


for i in range(4):

    for j in range(3):
        label = Label(inner_frame, anchor="center", image=img, bg="green")
        label.grid(column=j, row=i)
        label_txt = Label(inner_frame, anchor="center",
                          text="item1 \n Price - $20.00", bg="white")
        label_txt.grid(column=j, row=i, sticky='WES')
        j += 1
    i += 2
Lokesh Thakur
  • 138
  • 1
  • 1
  • 9
  • Use the class that I wrote [here](https://stackoverflow.com/a/66215091/11106801). The problem is that in your code `inner_frame` is `None` and you are packing it inside a canvas. It is possible to make your code work if you remove the `.pack(fill=Y, expand=1)` on this line: `inner_frame = Frame(my_canvas).pack(fill=Y, expand=1)` – TheLizzard May 16 '21 at 14:35

0 Answers0