(Tkinter) How do I display an image link as a button?

I want to display an image (that is a link) as a button. All the solutions I’ve seen are for images that are already DOWNLOADED into the computer itself (e.g. image2.png). However, the users that I’m distributing the program to would not have the image with the same file name downloaded on their computers, so I used an image link instead (e.g. https://cdn2.iconfinder.com/data/icons/flat-ui-icons-24-px/24/eye-24-256.png), but it does not work. How do i display an image on the button using a link like that?

This was what I tried from the internet:

from tkinter import *
from tkinter.ttk import *

# creating tkinter window
root = Tk()

photo = PhotoImage(file = r"https://cdn2.iconfinder.com/data/icons/flat-ui-icons-24-px/24/eye-24-256.png")
photoimage = photo.subsample(3, 3)
Button(root, text = 'Click Me !', image = photoimage,
                    compound = LEFT).pack(side = TOP)

root.mainloop()

The error I got:

_tkinter.TclError: couldn't open "https://cdn2.iconfinder.com/data/icons/flat-ui-icons-24-px/24/eye-24-256.png": no such file or directory

I think it search image on your PC.
I found this, an other way to import image, maybe it should work

1 Like

Sorry, I forgot to update that I’ve already found an answer to this a few days ago:

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

root = tk.Tk()
URL = "https://www.pinclipart.com/picdir/big/65-654632_setting-icon-clipart-png-download.png"
u = urllib.request.urlopen(URL)
raw_data = u.read()
u.close()

im = Image.open(BytesIO(raw_data))
im = im.resize((50,50),Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)

button = tk.Button(image=photo,width=50,height=50,compound="c")
button.image = photo
button.pack()

root.mainloop()

Thanks for replying though!