Python插入图像到Tkinter文本窗口

2024-09-19 20:35:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python创建了一个简单的聊天框,我想在一个TKinter文本小部件中插入一个图像(图释)。我用这个代码试过了:

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

上面代码的输出是

^{pr2}$

而不是图像。在


Tags: 代码图像image文本selfimg部件tkinter
2条回答

我不是百分之百确定,但我认为你需要使用^{}。比如:

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

应该会成功的。在

我用的是:

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

相关问题 更多 >