Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Tutorials listed in this section have not been reviewed nor are affliated by Code Forum. It is the sole responsbility of the authour to properly maintain and ensure information is accurate.

Python Example of tkinter using pillow to get and display images from web

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

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom