1

How can I make a text entry widget over picture in tkinter using python?
The code I am using:

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

It can make a button (OK) , why it can't make entry text widget?

4
  • you are not packing your entry. Commented Jul 17, 2017 at 11:20
  • also, don't mix geometry managers.(pack, place etc.) choose one and stick to it. Commented Jul 17, 2017 at 11:21
  • @Lafexlos really thank you, I missed that line. Commented Jul 17, 2017 at 11:22
  • @Lafexlos do you know how can I change the position of that text entry widget? Commented Jul 17, 2017 at 11:23

1 Answer 1

3

You forgot to pack the Entry field, just try something like:

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

And customize the position and behaviour as you prefer.

Sign up to request clarification or add additional context in comments.

5 Comments

How can I change position of it?
If you finally use pack as a geometry manager (using only one as @lafexlos suggested) then you can customize position, size, etc. of it by changing its configuration parameters. You will find more of this here
I still didn't get how to change position of it.
Here you will find some layout examples of the packgeometry manager, otherwise if you prefer to use another one, this answer can help you to understand their differences.
I got it myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.