python - 使用 python 在 tkinter 中的图片上添加文本输入小部件

标签 python tkinter

如何使用 python 在 tkinter 中的图片上制作文本输入小部件?
我正在使用的代码:

from tkinter import *
from PIL import ImageTk, Image
import os

root = Tk()
root.title('Title')
E1 = Entry(root, bd = 5,show='*') # tried this line of code but it didn't worked
img = ImageTk.PhotoImage(Image.open("path/to/image.png"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
c = Button(text="        OK         ")
c.place(relx=0.95, rely=0.98, anchor=SE)
root.mainloop()

可以制作按钮(确定),为什么不能制作输入文本小部件?

最佳答案

您忘记打包条目字段,只需尝试以下操作:

E1 = Entry(root, bd = 5,show='*') 
E1.pack(side=BOTTOM, fill=BOTH, expand=YES)

并根据您的喜好自定义位置和行为。

关于python - 使用 python 在 tkinter 中的图片上添加文本输入小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45142786/

相关文章:

python - 在 Python 中,为什么不能用 lambda 编写累加器生成器?

python - 如何使用 python PIL 获取图像中的颜色集

python - 需要帮助每分钟更新一个 tkinter 函数

Python tkinter 标签

python - Tkinter Python 删除垂直空格

python - 为什么 Tkinter 的单选按钮在使用 StringVar 而不是 IntVar 时都开始选中?

python - 使用 django.contrib.auth 限制对 Ajax 服务的访问

javascript - 使用 Python 'runJavascript' 输入更新谷歌地图标记位置

python - 使用单线程时 Queue.full() 是否可靠?

python - 在 Python 中使用 Tkinter 时程序挂起