【问题标题】:Add text entry widget over picture in tkinter using python使用python在tkinter中的图片上添加文本输入小部件
【发布时间】:2017-07-17 11:14:55
【问题描述】:

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

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()

可以做一个按钮(OK),为什么不能做entry text widget?

【问题讨论】:

  • 你不是packing你的条目。
  • 另外,不要混合几何管理器。(打包、放置等)选择一个并坚持下去。
  • @Lafexlos 真的谢谢你,我错过了那条线。
  • @Lafexlos 你知道如何更改文本输入小部件的位置吗?

标签: python tkinter


【解决方案1】:

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

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

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

【讨论】:

  • 如何改变它的位置?
  • 如果您最终使用pack 作为几何管理器(仅使用@lafexlos 建议的一个),那么您可以通过更改其配置参数来自定义它的位置、大小等。你会发现更多这个here
  • 我还是不知道怎么改变它的位置。
  • Here 你会找到一些packgeometry 管理器的布局示例,否则如果你喜欢使用另一个,这个answer 可以帮助你理解它们的区别。
  • 我自己弄的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多