-2

in tkinter you can preset a text in an entry box with inserting the text, but the problem then is, that you have to delete that preset text, if you want to input some other text without the already preset one. Its really hard for me to describe it, but I hope you understand what I mean. Basically I want a preset text in an entry box, but if the entry box is clicked, then I want the preset text to disappear. Is that possible in tkinter?

  • The general term for this functionality is *placeholder text*, you'll find various other answers here under that search term. – jasonharper Aug 19 '21 at 13:13

1 Answers1

1

Try this:

my_entry = tk.Entry(window)
my_entry.insert(tk.END, "default text")
my_entry.pack()
my_entry.bind("<Button-1>", lambda a: my_entry.delete(0, tk.END))

When the entry widget is clicked, it gets cleared

Roni
  • 597
  • 5
  • 21