2 years ago
#53715
zChris128
How to add multiple pictures into Tkinter Text-widget? (python)
I'm making this app, and I need to display a bunch of images alongside titles. I haven't done the title part yet because I ran into a problem.
I'm using a for loop to add all the images into this Text-box widget, which allows me to scroll through all the images once they've been added with the loop.
When the loop finishes going through all 25 pictures, only the last picture added is shown in the textbox and it's all the way at the bottom. It looks like this:
You can see that the image is all the way at the bottom of the screen and there's only one. It appears that its placing all the images, but all of them except for the last one are invisible.
I've done all I could but I couldn't wrap my head around why. Does anybody know?? Here's the code:
# the textbox was made here
self.display = Text(self.frame, font=('Roboto', 15), bg='#c8cbcc', borderwidth=0, highlightthickness=0)
self.display.grid(row=0, column=0, sticky='nsew', ipadx=200)
for i in range(len(thumbnails)):
urllib.request.urlretrieve(thumbnails[i], 'thumbnails/img{}.jpg'.format(i))
# get image
img = Image.open(('thumbnails/img{}.jpg'.format(i)))
img = img.crop([0, 60, 480, 300])
img = img.resize((200, round(200 / 1.3333)))
global image
image = ImageTk.PhotoImage(img)
# self.display.insert(END, '\n\t\t')
self.display.image_create(END, image=image)
self.display.config(state='disabled')
python
tkinter
textbox
0 Answers
Your Answer