I want to create a loop to create several buttons, and put a different image in each button. but it shows that on the last button, -noted: when I run in (debug) step by step, it works. -it's been two days since I search on google thank you in advance
from tkinter import *
win = Tk()
win.geometry("800x600")
win.title("hhh")
ls = ['/home/decode/Images/ImageDB/tom.png', '/home/decode/Images /ImageDB/aub.png','/home/decode/Images/ImageDB/res.png']
z=0
#g= ls[z]
for i in range(3):
g= ls[z]
img = PhotoImage(file=g)
btn = Button(win, image=img)
btn.pack()
z+=1
win.*mainloop*()
You want to use the PIL library and PhotoImage, for example: