How to set default text for a Tkinter Entry widget?

TkinterPythonServer Side ProgrammingProgramming

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.

raja
Published on 26-Mar-2021 15:01:43
Advertisements