Search code examples
pythontkinterinsertdefaulttkinter-entry

How to make default text in entry that disappears


For instance:

from Tkinter import *
root = Tk()

e1 = Entry(root)
e1.insert(END, "ex. new file")  #would like to make this text disappear when clicked
e1.grid(row=0, column=0)

root.mainloop()

Where the text "ex. newfile" disappears when clicked upon, leaving a blank entry field.


Solution

    1. Create a boolean flag that monitors if the entry has been accessed; set it to False,
    2. Bind "<Button-1>" to a function that clears the entry if it has not been accessed yet, and changes the flag to True.