In this tutorial, we will learn about Python Tkinter Entry. Tkinter Entry widget is used to get line entry from the user. We cannot get multiple line entry using the Python Tkinter Entry widget. There is a separate widget to get multiple line entry called Text widget.

Syntax to add Python Tkinter Entry:

w = Entry (master, options)   
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program:

from tkinter import *  
  
top = Tk()  
  
top.geometry("400x200")  

username = Label(top, text = "UserName").place(x = 30,y = 50)  
  
password = Label(top, text = "Password").place(x = 30, y = 90)  
  
sbmitbtn = Button(top, text = "Login",activebackground = "skyblue", activeforeground = "white").place(x = 30, y = 130)  
  
usernameE = Entry(top).place(x = 100, y = 50)   
  
passwordE = Entry(top).place(x = 100, y = 90)   
  
top.mainloop() 

Output:

Python Tkinter Button

Various possible options in Python Tkinter button:

OptionDescription
bgThis option helps us to set background colour displayed behind the widget.
bdThis option helps us to set the width of the border around the widget. By default size of the border is 2px.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
exportselectionText of entry widget automatically copied to clipboard. You can stop it from coping by setting exportsection to 0.
fgThis option helps us to set the color of the text in the entry widget.
fontThis option helps us to set the style of font.
justifyThis helps us to automatically organize the text in multiple lines.
widthThis helps us to set the width of the widget.
reliefThis helps us to set the style of the border by which is default Flat.
showThis helps us to show text inside an entry widget in some other type. for example, in case of the password, we show (*).

Python Tkinter Entry Functions:

There are various Python Tkinter Entry functions available. Which makes it so easy to use entry widget in our application these functions are as follow.

FunctionDescription
get()This function helps us to get a user-entered text from the entry widget.
delete ( first, last=None )This function helps us to delete specified characters from the text in the entry.
icursor(index)This function helps us to set the position of the insertion cursor.
index(index)This function helps us to set the position of the cursor on the left side of character at the specified index number.
insert(index,s)This function helps us to add the specified string before the character at the specified position.
select_clear()This function helps us to deselect the selection if something is selected.
select_present()This function will return true if something is selected in the entry widget otherwise false.
select_range(start,end)This function helps us to select text in the entry between the specified index range.
select_to(index)This function helps us to select all the characters from the beginning to the specified index.