Skip to content Skip to sidebar Skip to footer

How To Embed An Image In A Text Widget

I know it is possible to embed an image in a Tkinter text widget, but I've been unable to find some simple example code. Specifically, I need to embed a jpg, so according to the do

Solution 1:

PhotoImage only handles GIF and PGM/PPM files. In order to use JPEG with Tkinter, you can use the Python Imaging Library (PIL) to create a PhotoImage.

from PIL import Image, ImageTk

img = Image.open("yourimg.jpg")
photoImg = ImageTk.PhotoImage(img)

Alternatively you could just one of the other supported formats for PhotoImage if possible.

Post a Comment for "How To Embed An Image In A Text Widget"