How to set default text for a Tkinter Entry widget?


Tkinter Entry widget is used to print and display a single line of text taken from the user Input. It is used for many applications such as creating login forms, signup forms, and other user interaction forms.

We can set the default text for the Entry Widget using insert() function by passing the default text as the argument.

Example

In this example, we have created an Entry widget that has a default text.

#Import the tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry
win.geometry("650x250")

#Create an Entry Widget
entry= Entry(win)
entry.insert(END, 'Enter any Text')
entry.pack()

win.mainloop()

Output

Running the above code will set the default text for entry widget.

Updated on: 26-Mar-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements