-1

I am making a software login page in Python 3.8 with Tkinter.
How can I add placeholder in Tkinter Entry like the one in this image?

enter image description here

With this code:
E1 = Text(M, bd=0, height=35, width=1000, font=("Calibri 20"), bg="ghost white")
E1.pack(side=LEFT)

2 Answers2

3

this should work:

from tkinter import *


def focus_out_entry_box(widget, widget_text):
    if widget['fg'] == 'Black' and len(widget.get()) == 0:
        widget.delete(0, END)
        widget['fg'] = 'Grey'
        widget.insert(0, widget_text)


def focus_in_entry_box(widget):
    if widget['fg'] == 'Grey':
        widget['fg'] = 'Black'
        widget.delete(0, END)


entry_text = 'First name'
my_entry = Entry(font='Arial 18', fg='Grey')
my_entry.insert(0, entry_text)
my_entry.bind("<FocusIn>", lambda args: focus_in_entry_box(my_entry))
my_entry.bind("<FocusOut>", lambda args: focus_out_entry_box(my_entry, entry_text))
my_entry.pack()
mainloop()
0

You just have to set default value for the entry:

ui = Tk()

e= Entry(ui)
e.insert(0, 'text')
e.pack()
Sven
  • 1,014
  • 1
  • 11
  • 27