A class LabelImage to show images in tkinter easily

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()
Images in tkinter easy

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()

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.