Creating User-defined Entry Widgets

Creating User-defined Entry Widgets

In this tutorial, we will see how can we create entry widgets and the number of entry widgets will be defined by the user itself from the screen.

Python has many GUI libraries and tkinter is one the best among them and it’s very easy to learn and use, so we will use tkinter here.

We have put the source code with detailed explanation at every line and you will not face any problem.



Source Code


# the tkinter module has always to be imported as it contains the 
# Tk toolkit
from tkinter import *
# to initialize the tkinter module we need to create a root 
widget and this should be the first widget
root = Tk()
# here we are setting the length and width of the screen
root.geometry("500x600")
# adding text with the label widget
Label(text="Enter the no of entry widget you want to create").pack()
# function to create entry widget on calling
def create():
    for x in range((init_val.get())):
        Entry(root).pack(pady=10)
# declaring type of variable for entry widget
init_val = IntVar()
# creating entry widget to take value for no of entry widgets to
# be created
init_ent = Entry(root, textvariable=init_val).pack()
# creating a button to call the create function
Button(text="Create Now", command=create).pack()
# calling root
root.mainloop()

Outputs


1. Just runs the program

2. Setting the value as “2”

3. Clicking on “Create Now” Button



4. Entered “8” and clicked on “Create Now” button


Thanks for being here, if you want any source code then you can comment here


Run Python Online

Also read:




Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you