pythontkinter

Keep placeholder after typing and deleting something in a python Tkinter Entry?


This is my code:

date.insert(0, 'yyyy-mm-dd')
date.bind("<FocusIn>", lambda args: history_Date_Entry.delete('0', 'end'))

How can I make the placeholder visible after someone type on it and delete the text?


Solution

  • try:
        from tkinter import *  # Python 3.x
    except ImportError:
        from Tkinter import *  # Python 2.x
    
    root = Tk()
    e = Entry(root)
    e1 = Entry(root) # dummy one
    e.insert(0, 'yyyy-mm-dd')
    e.bind("<FocusIn>", lambda args: e.delete('0', 'end'))
    e.bind("<FocusOut>", lambda args: e.insert('0', 'yyyy-mm-dd'))
    e.pack()
    e1.pack()
    root.mainloop()