Python将图像插入Tkinter文本小部件 [英] Python Insert Image to Tkinter Text Widget

查看:94
本文介绍了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)

应该可以解决问题.

这篇关于Python将图像插入Tkinter文本小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆