问题描述
是否可以在图像上添加文本小部件?换句话说,我需要有一个背景图片并且能够在该图片上写文字(覆盖).
Is it possible to have a text widget over an image? In other words, I need to have a background image and be able to write text on that image (overlaid).
推荐答案
无法用文本小部件覆盖图像,并使图像在小部件下可见.
It is not possible to overlay an image with a text widget, and have the image be visible under the widget.
您可以做的是使用 Canvas
小部件,在画布中显示图像,然后在画布上创建文本项.画布上的文本项是可编辑的,但您需要做一些工作来设置一些绑定.
What you can do instead is use a Canvas
widget, display the image in the canvas, and then create text items on the canvas. Text items on the canvas are editable, though you have to do a little work to set up some bindings.
这里有一个关于如何在画布上创建可编辑文本项的很好的解释:http://effbot.org/zone/editing-canvas-text-items.htm
There is a good explanation of how to create editable text items on a canvas here: http://effbot.org/zone/editing-canvas-text-items.htm
这篇关于Tkinter 中图像上的文本小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!