0

How to display image of "https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg" this url in my tkinter project. is there is any way to do that.

2 Answers 2

2

Below is an simple example using urllib.requrest.urlopen() and Pillow module to show image from URL:

from urllib.request import urlopen
import tkinter as tk
from PIL import ImageTk

image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg"

root = tk.Tk()
data = urlopen(image_url)
image = ImageTk.PhotoImage(data=data.read())
tk.Label(root, image=image).pack()
root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

1
import urllib.request
import os
savein='test.jpg'
try:
    urllib.request.urlretrieve('https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg',savein)
except:
    print('Network Issue')
# then use the Tkinter code to use that savein as image address
# os.remove(savein) for deleting it later

I guess we can't use the image directly from the internet since we are using the Tkinter. So download the image and then use it in the Label and then delete it if u want.

savein variable has the link for the image

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.