how to embed an image in a text widget

前端 未结 1 1180
我在风中等你
我在风中等你 2020-12-19 15:18

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 t

1条回答
  •  感情败类
    2020-12-19 15:35

    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.

    0 讨论(0)
提交回复
热议问题