Set default text in Tkinter Entry widget
In this tutorial, I will show you how easily we can set any text as the default text in the Tkinter Entry widget. You can also say that I will set placeholder text for Tkinter Entry widget.
We can do this by just using:
myEntry.insert(0, "I am default")
Here myEntry is my Tkinter entry widget variable.
Let’s see an example so that you can understand it.
import tkinter as tk newWindow = tk.Tk() newWindow.geometry("600x600+600+200") myEntry = tk.Entry(newWindow) myEntry.insert(0, "I am default") myEntry.pack() newWindow.mainloop()
That’s all and you are done.
If you run this you will see that the Entry will be showing a default text which is I am default
.
Output:
Note: you may notice that Tkinter insert function’s index might not work. I have set it 0 and it is an index. So your text should start with the beginning. But it will not work as expectation if you change the index. I suggest you to use raw string if you really want to change the starting position of the text.
Leave a Reply