1
votes

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

Output of the code above is

<PIL.JpegImagePlugin.JpegImageFile instance at 0x01AB5A30>

instead of the image.

2

2 Answers

3
votes

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)

should do the trick.

0
votes

I have made it using:

from Tkinter import *
from PIL import Image, ImageTk

self.myEmoticons.append(self.smiley)
self.bigText.image_create(END,image = self.myEmoticons[self.myEmoticonsCtr])
self.myEmoticonsCtr=self.myEmoticonsCtr + 1