Tkinter List of Canvases

ChalaoAdda chalao.adda at gmail.com
Tue Nov 10 05:01:16 EST 2020


Hello,

I have a list of canvas of images. I would like to display all the images. But it displays the last image. Here is my code.

from tkinter import *
from PIL import Image, ImageTk

root = Tk()

canvas_width = 265
canvas_height = 130
canvases = []

r, c = 0, 0

for tile in tiles:
    img = tile.image
    photo = ImageTk.PhotoImage(image=img)
    can = Canvas(root, width=canvas_width, height=canvas_height)
    can.create_image(0, 0, image=photo, anchor=NW)
    canvases.append(can)
    can.grid(row=r, column=c)

   c += 1
    if c % 5 == 0:
        r += 1
        c = 0


root.mainloop()

Please help.
Thanks.


More information about the Python-list mailing list