How to set default text for a Tkinter Entry widget
Use Entry.insert
. For example:
try: from tkinter import * # Python 3.xexcept Import Error: from Tkinter import * # Python 2.xroot = Tk()e = Entry(root)e.insert(END, 'default text')e.pack()root.mainloop()
Or use textvariable
option:
try: from tkinter import * # Python 3.xexcept Import Error: from Tkinter import * # Python 2.xroot = Tk()v = StringVar(root, value='default text')e = Entry(root, textvariable=v)e.pack()root.mainloop()
For me,
Entry.insert(END, 'your text')
didn't worked.
I used Entry.insert(-1, 'your text')
.
Thanks.