aboutsummaryrefslogtreecommitdiff
path: root/test/placeholder.py
blob: 7b425c05952e74d43c437e7e529086f2b52a50af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import tkinter as tk

root = tk.Tk()

placeholder = 'Your text here'

def erase(event=None):
    if e.get() == placeholder:
        e.delete(0,'end')
def add(event=None):
    if e.get() == '':
        e.insert(0,placeholder)

e = tk.Entry(root)
e.pack(padx=10,pady=10)

dummy = tk.Entry(root) #dummy widget just to see other widget lose focus
dummy.pack(padx=10,pady=10)

add()
e.bind('<FocusIn>',erase)
e.bind('<FocusOut>',add)

root.mainloop()