This code shows how to obtain and display a GIF image from an internet website using the Tkinter GUI toolkit that comes with the Python installation.

Dani AI

Generated

's post says a GIF was meant to be shown but the snippet is missing; 's "What code?" is the right question. Two reliable options are supplied below: a pure-Tkinter approach that needs no external packages (works for GIFs), and a Pillow-based approach that handles PNG/JPEG and gives more control.

Pure Tkinter (GIF only, no dependencies):

import tkinter as tk
import urllib.request
import base64

url = "https://example.com/image.gif"

root = tk.Tk()
data = urllib.request.urlopen(url).read()
b64 = base64.b64encode(data).decode('ascii')
photo = tk.PhotoImage(data=b64)
label = tk.Label(root, image=photo)
label.image = photo    # keep a reference to prevent GC
label.pack()
root.mainloop()

Pillow (recommended for general image formats):

import tkinter as tk
from PIL import Image, ImageTk
import io, urllib.request

url = "https://example.com/image.png"

root = tk.Tk()
data = urllib.request.urlopen(url).read()
pil = Image.open(io.BytesIO(data))
tkimg = ImageTk.PhotoImage(pil)
label = tk.Label(root, image=tkimg)
label.image = tkimg    # keep a reference to prevent GC
label.pack()
root.mainloop()

Troubleshooting notes: use tkinter (lowercase) on Python 3; install Pillow with pip install pillow when using the second method. If the remote host blocks generic requests, wrap the URL in urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}). Keep the PhotoImage/ImageTk reference on the widget (e.g., label.image = ...) or the image will disappear. Animated GIFs require frame-by-frame updates (PhotoImage shows only one frame by default); use PIL.ImageSequence or repeatedly update the label with after() for animation. Network errors (HTTPError/URLError) should be caught and handled in production code.

What code?

commented: The magical and invisible code. I wish I could code like that. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.