Python Tkinter – Entry Widget
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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
The Entry Widget
The Entry Widget is a Tkinter Widget used to Enter or display a single line of text.
entry = tk.Entry(parent, options)
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.