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.
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()
Various possible options in Python Tkinter button:
|bg||This option helps us to set background colour displayed behind the widget.|
|bd||This option helps us to set the width of the border around the widget. By default size of the border is 2px.|
|cursor||This option helps us to set the style of cursor like an arrow, dot etc|
|exportselection||Text of entry widget automatically copied to clipboard. You can stop it from coping by setting exportsection to 0.|
|fg||This option helps us to set the color of the text in the entry widget.|
|font||This option helps us to set the style of font.|
|justify||This helps us to automatically organize the text in multiple lines.|
|width||This helps us to set the width of the widget.|
|relief||This helps us to set the style of the border by which is default Flat.|
|show||This 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 Methods:
After learning about various available options in Python Tkinter Entry. Its time to check out some available methods for Python Tkinter Entry widget.
|get()||This method helps us to get a user-entered text from the entry widget.|
|delete ( first, last=None )||This method helps us to delete specified characters from the text in the entry.|
|icursor(index)||This method helps us to set the position of the insertion cursor.|
|index(index)||This method helps us to set the position of the cursor on the left side of character at the specified index number.|
|insert(index,s)||This method helps us to add the specified string before the character at the specified position.|
|select_clear()||This method helps us to deselect the selection if something is selected.|
|select_present()||This method will return true if something is selected in the entry widget otherwise false.|
|select_range(start,end)||This method helps us to select text in the entry between the specified index range.|
|select_to(index)||This method helps us to select all the characters from the beginning to the specified index.|