how to show an image in tkinter code example

Example 1: python tkinter image

import tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()
img = Image.open("path\\to\\imgage.jpg")
img = img.resize((250, 250))
tkimage = ImageTk.PhotoImage(img)
tk.Label(root, image=tkimage).grid()

Example 2: how to add a image in tkinter

from tkinter import *
root=Tk()
img=PhotoImage(file='sunshine.jpg')
Label(root,image=img).pack()
root.mainloop()

Example 3: image in tkinter

import tkinter as tk
window = tk()
canvas = Canvas(window, width=300, height=300)
image = PhotoImage('path')
canvas.create_image(height=40, width=40, img=image)

Example 4: image in tkinter

pip install pillow