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
Also read:
- See connected wifi passwords using Python
- Simple Text-To-Speech In Python
- GUI Calculator Using Python tkinter
- Password Generator Application
- GUI Stone Paper Scissor Game: Python
- Displaying Images in Tkinter
- GUI Age Calculator
- Changing Screen Size: Tkinter
- Simple Music Player Using Python
- Adding three matrices
- Auto-Login with Python