How to Create a Tkinter Entry Widget

Published December 11, 2021

The Python Tkinter entry widgets allow the user to enter a single-line text string into the application. However, this does not limit the user to entering multiple lines of text strings into the application; these widgets automatically scroll the entered text if it exceeds the widget display area. In this post, we will look at the Python Tkinter entry widget for both the text strings and the password.

 

How to Create a Tkinter Entry Widget

Creating a Tkinter entry widget is very easy. You only need to follow the following syntax.

W = Entry (root, options)

These options specify the attributes of the widget. Here are some commonly used Tkinter entry widgets:

  • Bg-specifies the background color of the widget.

  • Bd-specifies the border of the widget

  • Cursor- specifies the behaviour of the cursor when it hovers over the widget.

  • Exportselection: allows the text entered not to be copied to the clipboard by default.

  • Fg-specifies the font color.

  • Font-Specifies the font of the text entered.

  • Highlighbackground-specifies the color used for the traversal highlight region when the widget does not have an input focus.

  • Highlightcolor: represents the color that is used for the traversal highlight rectangle drawn around the widget.

  • Highlightthickness- When the widget has the input focus, this value indicates the width of the highlight rectangle drawn around the widget's perimeter.

  • Insertbackground: specifies the background color of the widget area covered by the insertion cursor.

  • Insertborderwidth: The border of a 3-D border to create a general insertion pointer is represented by this non-negative number.

  • Insertofftime-specifies the total time that the cursor should remain off

  • Justify- specifies the arrangement and organization of the text.

  • Selectbackground-specifies the font color of the task selected

  • Show-shows the entry text or some other type of string

  • Width- shows the width of the text or image displayed

To enable the Tkinter entry widget to work, the following methods are implemented:

  • get()-returns the entered text as a string

  • delete ()-removes the characters entered.

  • insert () -inserts the "name" before  the provided "index".

 

An Example of a Tkinter Entry Widget 

In this example, the Tkinter entry widget is used to input a text string

from tkinter import *

top = Tk()

L1 = Label(top, text="Enter Text here")

L1.pack( side = LEFT)

E1 = Entry(top, bd =5)

E1.pack(side = RIGHT)

top.mainloop()

 

 

How to add Tkinter entry box

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

671 Views