Entry box text clear when pressed Tkinter

Assuming you’ve got your default text sorted out, you want to create an Event binding somewhere, with the general format of the comment above, not sure why it’s not an answer, because it’s right:

import tkinter as tk

root = tk.Tk()
e = tk.Entry(root)
e.insert(0, "some text")

def some_callback(event): # note that you must include the event as an arg, even if you don't use it.
    e.delete(0, "end")
    return None

e.bind("<Button-1>", some_callback)

e.pack()

Finally, http://effbot.org is your friend:
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

EDIT: Additional info for OP from comment.
If you have multiple entries and you need to clear each one individually, you can simply refer to the widget that called the bound method using

event.widget

Your callback could then work as follows:

def some_callback(event):
    event.widget.delete(0, "end")
    return None

Leave a Comment