Skip to content Skip to sidebar Skip to footer

How To Add A Placeholder In Tkinter

How would I add a placeholder to an entry in tkinter? I don't believe it has a placeholder function like HTML for example. I figured out that to make the text disappear when you cl

Solution 1:

U can't add placeholder like HTML as far as i know, but u can make similar behavior. When you make entry you can do something like>

from tkinter import *   

def clear_entry(event, entry):
    entry.delete(0, END)

root = Tk()

entry = Entry(root)

entry.pack()
placeholder_text = 'some text'
entry.insert(0, placeholder_text)

entry.bind("<Button-1>", lambda event: clear_entry(event, entry))

root.mainloop()

P.S: I've wrote this from my head , haven't tested it

Post a Comment for "How To Add A Placeholder In Tkinter"