How to use the Entry widget in Tkinter?

The Entry widget is a single-line text widget defined in Tcl/Tk toolkit. We can use the Entry widget to accept and display single-line user input.

In order to use the Entry widget, you have to first create an Entry widget using the constructor Entry(parent, width, **options). Once we've defined our Entry widget, we can configure its properties such as font-properties, color, width, etc., using the configure() method.


Let use create an Entry widget to accept the username and display it in the window.

# Import the required libraries
from tkinter import *

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

# Set the size of the tkinter window

def show_name():
   # Create a Label widget
   label = Label(win, text="Hello " + str(entry.get()) + "👋", font=('Calibri 25')).pack(pady=20)
   entry.delete(0, END)

# Create a Label
Label(win, text="Enter Your Name").pack()

# Create an Entry widget
entry = Entry(win, width=25)

Button(win, text="Submit", command=show_name).pack()



When you run the above code, it will display a window with an Entry widget and a button. Type your name in the given Entry widget and click the button to show the message on the window.