Displaying three images from the web using pillow and tkinter
Python:
# Do the imports
import tkinter as tk
from PIL import Image, ImageTk
from urllib.request import urlopen
import io
# Iniate the root window
root = tk.Tk()
# Empty list to keep a reference to the images
images = []
# Setup a list of tuples with sizes
sizes = [(100,100), (150,150), (200,200)]
# get the image from an url
img_url = urlopen('https://my-python.org/images/png/ratt.png')
# Readin the images
img = Image.open(io.BytesIO(img_url.read()))
# A loop to display three images of different sizes
for size in sizes:
img = img.resize(size, Image.Resampling.LANCZOS)
image = ImageTk.PhotoImage(img)
# Append images to list to keep reference
images.append(image)
# Create the labels
label = tk.Label(root, image=image)
label.pack()
root.mainloop()