Display jpg images in python

I am creating a simple tool for adding album art covers to mp3 files in python. So far, I’m just working on sending a request to Amazon with the name of the artist and album, and I also get the resulting list, as well as searching for the actual images for each result. I want to show a simple frame with a button / link for each image and a skip / cancel button.

I have done several searches, but I can’t find examples that I can use as a base.

  • I want to display images directly from the Internet. I.e. using urllib to open and read bytes in memory, not to go through a file on disk
  • I want to display images as buttons preferably

All the examples seem to focus on working with files on disk, not just the buffer. The TK documentation in the python standard library does not seem to cover the main Button widget. This seems like an easy task, I just could not find the right documentation.

+5
source share
2 answers

you can change this with urllib.urlopen(). But I do not know (as I did not test it) if you can do this step without saving the file (image) locally. But IMHO urlopenreturns a file descriptor that can be used in tk.PhotoImage().

For jpg files in PhotoImage you need PIL :

from PIL import Image, ImageTk
image = Image.open("test.jpg")
photo = ImageTk.PhotoImage(image)
+3
source

To display jpg in Python check PIL

-1

All Articles