ENTRY IN TKINTER


In this tutorial, we will learn about the entry widget in Tkinter and how we can set them with their respective labels followed by a handy example





What is Entry in Tkinter?

The Entry widget in Tkinter is used to accept one-line text strings as an input. In order to create the entry field, we declare it as:

entry_tkinter = Entry( window, features)

Discover how to create visually stunning and feature-rich applications by using Python’s built-in Tkinter GUI toolkit

Entry features and properties are:

1 bg Shows the background color of the entry field
2 bd Shows the border width of the entry field
3 cursor You can use the cursor as different shapes on the screen as circle, dot etc.
4 exportselection The text that you place inside the entry field will be always copied to the
clipboard. To avoid this, set exportselection to 0.
5 fg Shows the color of the text entered in the entry field.
6 font Displays the type of font that you want to use in your entry field.
7 highlightbackground It represents the color to display in the traversal highlight region when the widget does not have the input focus.
8 highlightcolor It shows the highlight color of the entry widget when it is clicked.
9 justify Justifies the text present inside the entry field.
10 relief Defines the border style to be used for the entry widget.
11 selectbackground Displays the background of the text selected
12 selectborderwidth Dsiplays the width of the border present on the text selected.
13 selectforeground Displays the font color of the text selected
14 show Used to display different types of text entry. In order to enter password
in the field, declare show=”*”
15 state This represents DISABLED or ACTIVE state of the entry widget
16 textvariable In order to fetch text from your entry field, set this option to StringVar
17 width Shows the width of the checkbutton.
18 xscrollcommand If users want to add more text to the entry field in a horizontal direction,
make sure you use this option.




Creating Entry Fields with Labels

import tkinter as tk
screen = tk.Tk()

#Screen size
screen.geometry('300x300')

#Name Label
label1_tk = tk.Label(screen, text="Name")
label1_tk.pack()

#Name Entry
entry1_tk = tk.Entry(screen, bd = 5)
entry1_tk.pack()

#password Label
label1_tk = tk.Label(screen, text="Password")
label1_tk.pack()

#Password Entry
entry2_tk = tk.Entry(screen, bd = 5, show="*")
entry2_tk.pack()

screen.mainloop()

Output:

You can fill the text fields too:

Enter Tkinter 2

References have been used from here