1

This is my code:

from tkinter import *
from PIL import Image, ImageTk


im = Image.open(r"1asd.jpg")

root = Tk()
tkimage = ImageTk.PhotoImage(im)
lst = []
for i in range(1, 100):
    A = Label(root, image=tkimage, text="File number "+str(i), compound=RIGHT)
    A.config(font=("Courier", 44))
    lst.append(A)

for i in lst:
    i.pack()
root.mainloop()

the problem is, that I can't see all the images because there are too much from them. how can I make a scrollbar? I tried to use the "Listbox" object but it doesn't let me place an image next to the text.

clavlav12
  • 74
  • 1
  • 7
  • you can put images on `Canvas` and scroll canvas. Or you will have to find out how to use Fame on Canvas to create Scrolled Frame - and then you can put your Labels in this [Scrolled Frame](https://github.com/furas/python-examples/tree/master/tkinter/scrolled-frame-canvas) – furas Apr 14 '19 at 12:17

1 Answers1

2

Try to do something like this

from tkinter import *
from PIL import Image, ImageTk

root = Tk()
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
w = 1000
h = 1000
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.update()
canvas = Canvas(root, bg="Black", width=root.winfo_width(), height=root.winfo_height())
canvas.pack()

im = Image.open("home.png")
tkimage = ImageTk.PhotoImage(im)
lst = []
y = 0
for i in range(1, 100):
    label = Label(canvas,image=tkimage, text="File number " + str(i), font=("Courier", 44), compound=RIGHT)
    canvas.create_window(0, y, window=label, anchor=NW)
    y += 60

scrollbar = Scrollbar(canvas, orient=VERTICAL, command=canvas.yview)
scrollbar.place(relx=1, rely=0, relheight=1, anchor=NE)
canvas.config(yscrollcommand=scrollbar.set, scrollregion=(0, 0, 0, y))

root.mainloop()

I used the Canvas for place all the labels and scroll them

Mat.C
  • 1,379
  • 2
  • 21
  • 43