The Wayback Machine - https://web.archive.org/web/20241127012556/https://www.geeksforgeeks.org/python-tkinter-entry-widget/
Open In App

Python Tkinter – Entry Widget

Last Updated : 21 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.
In Python3 Tkinter is come preinstalled But you can also install it by using the command: 
 

pip install tkinter


Example: Now let’s create a simple window using Tkinter
 

Python3
# creating a simple tkinter window
# if you are using python2 
# use import Tkinter as tk  

import tkinter as tk


root = tk.Tk()
root.title("First Tkinter Window")
root.mainloop()

Output :
 

python-tkinter1


 

The Entry Widget


The Entry Widget is a Tkinter Widget used to Enter or display a single line of text. 
 

Syntax : 

entry = tk.Entry(parent, options)


Parameters: 
 

1) Parent: The Parent window or frame in which the widget to display.
2) Options: The various options provided by the entry widget are: 
 

  • bg : The normal background color displayed behind the label and indicator. 
  • bd : The size of the border around the indicator. Default is 2 pixels. 
  • font : The font used for the text. 
  • fg : The color used to render the text. 
  • justify : If the text contains multiple lines, this option controls how the text is justified: CENTER, LEFT, or RIGHT. 
  • relief : With the default value, relief=FLAT. You may set this option to any of the other styles like : SUNKEN, RIGID, RAISED, GROOVE 
  • show : Normally, the characters that the user types appear in the entry. To make a .password. entry that echoes each character as an asterisk, set show=”*”. 
  • textvariable : In order to be able to retrieve the current text from your entry widget, you must set this option to an instance of the StringVar class.


Methods: The various methods provided by the entry widget are: 

  • get() : Returns the entry’s current text as a string. 
  • delete() : Deletes characters from the widget 
  • insert ( index, ‘name’) : Inserts string ‘name’ before the character at the given index. 
     


Example: 
 

Python3
# Program to make a simple 
# login screen  


import tkinter as tk
 
root=tk.Tk()

# setting the windows size
root.geometry("600x400")
 
# declaring string variable
# for storing name and password
name_var=tk.StringVar()
passw_var=tk.StringVar()

 
# defining a function that will
# get the name and password and 
# print them on the screen
def submit():

    name=name_var.get()
    password=passw_var.get()
    
    print("The name is : " + name)
    print("The password is : " + password)
    
    name_var.set("")
    passw_var.set("")
    
    
# creating a label for 
# name using widget Label
name_label = tk.Label(root, text = 'Username', font=('calibre',10, 'bold'))
 
# creating a entry for input
# name using widget Entry
name_entry = tk.Entry(root,textvariable = name_var, font=('calibre',10,'normal'))
 
# creating a label for password
passw_label = tk.Label(root, text = 'Password', font = ('calibre',10,'bold'))
 
# creating a entry for password
passw_entry=tk.Entry(root, textvariable = passw_var, font = ('calibre',10,'normal'), show = '*')
 
# creating a button using the widget 
# Button that will call the submit function 
sub_btn=tk.Button(root,text = 'Submit', command = submit)
 
# placing the label and entry in
# the required position using grid
# method
name_label.grid(row=0,column=0)
name_entry.grid(row=0,column=1)
passw_label.grid(row=1,column=0)
passw_entry.grid(row=1,column=1)
sub_btn.grid(row=2,column=1)
 
# performing an infinite loop 
# for the window to display
root.mainloop()

Output : 
 

python-tkinter-entry-widget


 

python-tkinter-entry-widget



Python Tkinter – Entry Widget – FAQs

What is the Use of Entry Widget in Tkinter Python? 

The Entry widget in Tkinter is used for entering or displaying a single line of text. It is commonly used in forms, dialogs, and for other input fields where the user is expected to input a short text string. This widget allows for basic text input from the user, such as names, addresses, or small numerical inputs.

How to Make an Entry in Tkinter?

Creating an Entry widget in Tkinter involves initializing the widget and then placing it on the main window or any other parent widget using layout managers like pack, grid, or place.

Example:

import tkinter as tk

root = tk.Tk()

entry = tk.Entry(root, width=20)
entry.pack()

root.mainloop()

What is the Difference Between Entry and Text Widget?

  • Entry Widget: It is used for single-line text inputs. It’s best for forms where the user inputs a small amount of text, such as a username or password.
  • Text Widget: This widget is used for multi-line text input. It allows for the editing of multiline text documents, formatting text, and other complex text operations, which makes it suitable for text editors.

How to Create a Text Input in Tkinter?

To create a basic text input field in Tkinter, you can use the Entry widget for single-line input or the Text widget for multi-line input.

Example using Text Widget:

import tkinter as tk

root = tk.Tk()

text_input = tk.Text(root, height=5, width=20)
text_input.pack()

root.mainloop()

What is the Readonly Entry Widget Used For?

A readonly Entry widget is used in scenarios where you want to display information that the user can select and copy but not modify. This is useful in applications where data integrity is crucial but the user needs to be able to see and interact with the data.

Example of Creating a Readonly Entry Widget:

import tkinter as tk

root = tk.Tk()

readonly_entry = tk.Entry(root, width=20)
readonly_entry.insert(0, "Read-only text")
readonly_entry.config(state='readonly')
readonly_entry.pack()

root.mainloop()

In this configuration, the user can see and copy the text from the entry but cannot change it, maintaining the data’s integrity while still providing interaction capability.



Previous Article
Next Article

Similar Reads

Python Tkinter - Validating Entry Widget
Python offers a variety of frameworks to work with GUI applications. Tkinter or Tk interface is one of the most widely used Python interface to build GUI based applications. There are applications that require validation of text fields to prevent invalid input from the user before the form is submitted. Python allows input validation by allowing va
5 min read
Validating Entry Widget In Python Tkinter
When developing graphical user interfaces (GUIs) in Python, Tkinter is a powerful and widely-used toolkit that simplifies the process. One of the common tasks in GUI applications is obtaining user input through form fields. Tkinter's Entry widget is designed for this purpose, allowing users to input text. However, ensuring the correctness of the en
7 min read
Tkinter | Adding style to the input text using ttk.Entry widget
Tkinter is a GUI (Graphical User Interface) module which is widely used to create GUI applications. It comes along with the Python itself. Entry widgets are used to get the entry from the user. It can be created as follows- entry = ttk.Entry(master, option = value, ...) Code #1: Creating Entry widget and taking input from user (taking only String d
2 min read
Tkinter - Read only Entry Widget
Python has a number of frameworks to develop GUI applications like PyQT, Kivy, Jython, WxPython, PyGUI, and Tkinter. Python tkinter module offers a variety of options to develop GUI based applications. Tkinter is an open-source and available under Python license. Tkinter provides the simplest and fastest way to develop a GUI application. Tkinter su
4 min read
How to Set the Default Text of Tkinter Entry Widget?
The Tkinter Entry widget does not have any text attribute that can be used to set the default text. Therefore, default text must be added to any text field in Tkinter using the following methods: Insert methodstringvar method Method 1: Using the insert method The tkinter module is imported. The root widget is created and this must be done before cr
2 min read
Change the position of cursor in Tkinter's Entry widget
A widget in tkinter, which is used to enter a display a single line of text is called an entry widget. Have you created an entry widget in tkinter which contains a lot of information? Is a lot of text causing an issue to you to move at any other position in it? Don't worry, we have a solution to this problem. What you need to do is to just set a bu
3 min read
How to Clear the Entry Widget After Button Press in Tkinter
The entry widget in Tkinter is a common input field that allows users to enter and edit a single line of text. Clearing the contents of this widget programmatically can enhance user interaction, especially after submitting or resetting a form. In this article, we will explore two different approaches to clear the entry after a button is pressed in
2 min read
How to Disable an Entry Widget in Tkinter?
In Tkinter, Entry widgets serve as a fundamental component for user input. However, there are instances in GUI applications where you may want to disable an Entry widget to prevent users from altering its contents. This article explores three distinct approaches to disable Entry widgets in Tkinter, each offering its unique advantages and use cases.
2 min read
How to Get the Value of an Entry Widget in Tkinter?
Tkinter, a standard GUI (Graphical User Interface) toolkit for Python, offers various widgets to create interactive applications. Among these widgets, the Entry widget allows users to input text or numerical data. Often, developers need to retrieve the value entered by the user in an Entry widget for further processing or validation. In this articl
2 min read
How to create a multiline entry with Tkinter?
Tkinter is a library in Python for developing GUI. It provides various widgets for developing GUI(Graphical User Interface). The Entry widget in tkinter helps to take user input, but it collects the input limited to a single line of text. Therefore, to create a Multiline entry text in tkinter there are a number of ways. Methods to create multiline
3 min read
How to resize an Entry Box by height in Tkinter?
In this article, we shall look at how can one resize the height of an Entry Box in Python Tkinter. An Entry Widget is a widget using which a user can enter text, it is similar to HTML forms. In Tkinter, the Entry widget is a commonly used Text widget, using which we can perform set() and get() methods. But the developer might always find it annoyin
3 min read
How to Use Entry Box on Canvas - Tkinter
There are various ways of creating GUI applications in Python. One of the easiest and most commonly used ways is through the use of the Tkinter module. Tkinter offers various widgets for creating web apps. One such widget is the Entry box, which is used to display a single line of text. Are you facing the issue of creating an entry box on the canva
5 min read
How To Print Entry Text Tkinter?
Tkinter is a popular GUI library in Python that allows developers to create desktop applications. One common task is retrieving and displaying the text entered by users. In this article, we'll go through the steps to create a simple Tkinter application that prints the text from an Entry widget in Python. Steps to Print Tkinter Entry TextTo print th
4 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Python | Menu widget in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself. Menus are the important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipu
2 min read
Progressbar widget in Tkinter | Python
The purpose of this widget is to reassure the user that something is happening. It can operate in one of two modes - In determinate mode, the widget shows an indicator that moves from beginning to end under program control. In indeterminate mode, the widget is animated so the user will believe that something is in progress. In this mode, the indica
2 min read
Python | PanedWindow Widget in Tkinter
Tkinter supports a variety of widgets to make GUI more and more attractive and functional. The PanedWindow widget is a geometry manager widget, which can contain one or more child widgets panes. The child widgets can be resized by the user, by moving separator lines sashes using the mouse. Syntax: PanedWindow(master, **options) Parameters: master:
3 min read
Python Tkinter - Toplevel Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in Python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter Toplevel widget A Toplevel widget is used to create a window on top of all other w
3 min read
Combobox Widget in tkinter | Python
Python provides a variety of GUI (Graphic User Interface) types such as PyQT, Tkinter, Kivy, WxPython, and PySide. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to understand. The word Tkinter comes from the Tk interface. The tkinter module is available in Python standard library which has to be impo
3 min read
Python Tkinter - ListBox Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter ListBox widget The ListBox widget is used to display different types of items. The
2 min read
Python Tkinter - Scale Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter Scale widget The Scale widget is used whenever we want to select a specific value
2 min read
Python Tkinter - Canvas Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs.Note: For more information, refer to Python GUI – tkinter Canvas widget The Canvas widget lets us display various graphics on the application
3 min read
Python Tkinter - MessageBox Widget
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy ta
2 min read
Python Tkinter - Menubutton Widget
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy ta
4 min read
Creating Tabbed Widget With Python-Tkinter
Python offers a range of GUI frameworks that can be used to develop GUI based applications in Python. The most widely used Python interface is Tk interface or tkinter( as renamed in Python 3.x) . The Tkinter module offers a wide range of widgets that can be used to develop GUI applications much faster and easier compared to the other interfaces off
5 min read
Python Tkinter - ScrolledText Widget
Tkinter is a built-in standard python library. With the help of Tkinter, many GUI applications can be created easily. There are various types of widgets available in Tkinter such as button, frame, label, menu, scrolledtext, canvas and many more. A widget is an element that provides various controls. ScrolledText widget is a text widget with a scrol
3 min read
Python Tkinter – How to display a table editor in a text widget?
In this article, we will discuss how to display a table editor in a text widget. Before moving ahead let's create a simple text widget first with the help of Tkinter. For the link to the Excel file used in the code click here. Text Widget The Text widget is used to show the text editor in the Tkinter window. A user can modify the text in the text e
3 min read
Python Tkinter - Frame Widget
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.
3 min read
Python Tkinter - Checkbutton Widget
The Checkbutton widget is a standard Tkinter widget that is used to implement on/off selections. Checkbuttons can contain text or images. When the button is pressed, Tkinter calls that function or method. Note: For more reference, you can read our article, What is WidgetsPython Tkinter OverviewPython Tkinter TutorialTkinter Checkbutton Widget Synta
5 min read
Hide Python Tkinter Text widget border
Tkinter is a standard GUI library for Python, providing tools to create graphical user interfaces easily. When designing interfaces, developers often encounter the need to customize widget appearances, including removing widget borders. Borders can sometimes clash with the desired aesthetic or layout of the application. This article explores what w
3 min read
three90RightbarBannerImg