1

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 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If it doesn't, we'll have to wait for @BryanOakley to come along -- He's the resident Tk/Tkinter expert around these parts.
0

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

1 Comment

Where's the rest of it? Could you provide a complete, minimal example of the working implementation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.