This is my class to show images in tkinter.
import tkinter as tk root = tk.Tk() class LabelImage: "Show images passed as argument" def __init__(self, imagepath): img = tk.PhotoImage(file=imagepath) self = tk.Label(root, image = img) self.image = img self.pack() im = LabelImage("banner.png") root.mainloop()
Show all the images in a folder
import tkinter as tk import os root = tk.Tk() class LabelImage: "Show images passed as argument" def __init__(self, imagepath): img = tk.PhotoImage(file=imagepath) self = tk.Label(root, image = img) self.image = img self.pack() def show_all(): for i in os.listdir(): if i.endswith(".png") or i.endswith(".PNG"): LabelImage(i) show_all() root.mainloop()