PyQt5 – Create a User form to get information
In this article we will see how we can create a user form in PyQt5. A user form is basically a dialog box that makes a user data entry more controllable and easier to use for the user. Sometimes while creating a large user interface application there is need of creating user form in order to get essential information.
Implementation steps :
1. Create a window class that inherits QDialog
2. Add window title and set its geometry
3. Create a QGropBox object
4. Create line edit to get the name, spin box to get the age and combo box to select the degree
5. Create a createForm method that will create a form
6. Inside the create form method, create a form layout and add rows
7. Each row should be has a label and the input method example name label and line edit for input, similarly label for degree and age and combo box and spin box for input.
8. Create a QDialogButtonBox for ok and cancel state
9. Add action to the button for acceptance and for rejection
10. If ok button is pressed just print all the information and if the cancel button is pressed window will get closed
Below is the implementation
Person Name : Geek Degree : BTech Age : 20
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