Python将图像插入Tkinter文本小部件

问题描述:

我正在用Python创建一个简单的聊天框,我想将图像(表情符号)插入TKinter文本小部件.我已经使用以下代码尝试过:

Im creating a simple chat box in Python and I want to insert an image(emoticons) to a TKinter text widget. I have tried it using this code:

img = Image.open("icon.jpg")
self.bigText.insert(END, img)  # bigText is the text widget

上面代码的输出是

<PIL.JpegImagePlugin.JpegImageFile instance at 0x01AB5A30>

而不是图像.

对此我不确定100%,但是我认为您需要使用

I'm not 100% sure on this, but I think you need to use image_create. Something like:

self.bigText.image_create(END, image=img)

应该可以解决问题.