Hey guys. This tutorial is about entry widget in python tkinter. you know what is tkinter library in python? In short this will help to build a custom software application. So, lets jump into it now.
What is Entry Widget we can develop using python language?
Entry widget is meant for taking a single line text strings from the user. This does not take a multiple line text. If a multiline text is required a text widget can be used. Label widget just displays the text but cannot be modified.
I will make here a detailed walkthrough of the entry widget and you can follow the tutorial here. Entry widget will help create an input to be taken from the user and make it more interactive. This will make out an application.
Syntax:
E = Entry(master, option,....)
Parameters:
master: This represents the parent window.
option: This represents the various options/Documentation available for this entry widget.
The code to create a simple Entry widget in python is given below. So, Lets first import required libraries for the creation of Entry widget. The required libraries are:
#Import tkinter library and its dependencies
from tkinter import *Then we will create an object of tkinter library. This object will help us to create application with entry widget. The code for it shown as below and let us follow the next steps now.
# Create an object for creating application that will help build it.
top = Tk()Then we will create a label widget that displays the name and which cannot be edited. This label widget appears at left hand side of the entry widget in the application window.
# Label widget with text Name and packed to left in the window.
L1 = Label(top, text="Name")
L1.pack( side = LEFT)Then we will create an Entry widget in the application. The code for entry widget creation and packing the widget can be seen below.
# Entry widget creation with border pixels of 5 and packed to the right in the window.
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)At last we will run the infinite loop as shown below.
# Run infinite loop that will display the window.
top.mainloop()Then we will see the complete code for creating entry widget as shown below.
Code to create Entry widget:
The complete code for creating entry widget is shown below. Try running the code from it and see if you can run it without any error with the output shown as below.
#Import tkinter library and its all dependencies
from tkinter import *
# Create an object of tkinter for building the application.
top = Tk()
# Label widget can be seen below which is packed to left hand side.
L1 = Label(top, text="Name")
L1.pack( side = LEFT)
# Entry widget creation which is packed at right hand side
# of label widget in the window created
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
# Run infinite loop that will display the window.
top.mainloop()The output of the above code is as shown below:
If you are enjoying reading the blog post please share it with others. I feel motivated in writing such content more and make project tutorials. Happy Learning!



0 Comments