Suppose I have 100 pictures. In zip / just in the folder. These pictures should consistently replace each other, being displayed in, ideally without repetitions, at the touch of a button. Tried to create a list of paths and list.pop (), swears that such a file does not exist, even through an absolute path, although the separate list and list.pop () work wonderfully, and the values ​​are output as it should.

Actually, how?

    1 answer 1

    from functools import partial from itertools import cycle from io import BytesIO from zipfile import ZipFile from tkinter import Tk, Label, Button from PIL import Image, ImageTk zip_file = ZipFile('images.zip', 'r') images = cycle(zip_file.namelist()) def change_image(label): with BytesIO(zip_file.read(next(images))) as data: with Image.open(data) as img: photo = ImageTk.PhotoImage(img) label.image = photo label.configure(image=photo) root = Tk() root.title('Demo') label = Label(root) label.pack() button = Button(root, text='Следующая картинка', command=partial(change_image, label)) button.pack() change_image(label) root.mainloop()