Simple Registration form using PyQt5 in PythonIn this tutorial, we'll look at how to utilise PyQt5 to develop a user form. A user form is essentially a dialogue box that gives the user additional control and ease of use while entering user data. It is occasionally necessary to create user forms while developing a big user interface application in order to gather crucial data. The Python programming language and the Qt library were combined to create the toolkit known as PyQt. As one of the most popular GUI Frameworks for Python, PyQt has a strong community and a tonne of excellent documentation. The fundamental components of user interfaces and GUI components are widgets. A label, button, menu, combo box, scroller, toolbar, file dialogue, etc. are examples of widgets. The PyQt framework must first be installed using the pip package manager before it can be used. To install the most recent version of PyQt, run the command below if pip is already installed on your computer : This particular form will mainly have 3 fields :
All these fields will have separate labels and text fields grouped together as a whole in the form. The degree component will also have a dropdown section in order to chose the degree that the user wants to pursue. Steps for implementation :
Walking through the code :Firstly, we will import all the modules that are required by our program in the starting only, from the standard Python library. These modules include QtWidgets and sys. Then, we will create a new window called window with an inherited class and will initialize by defining the constructor. Followed by setting the title of the window along with its geometry too. Next, we will create a new group box which will be used to contain all the elements or the widgets all together in a group. Then, we will create a spin box for the selection of age by the user followed by creating a combo box to select the degree they want to pursue. And then, we will add the dropdown items to the combo box to display on getting clicked. Next, we will create a line edit to enter editable text and will call the creatingForm() method to create a new form. Then, we will create a button box that will contains for two functions namely OK and Cancel. Then, we will add the respective actions for both the buttons of the group that needs to be performed on being clicked. Then, we will introduce a new main layout and form group box to it first, followed by adding the button box to the main layout. Next, we will create a new method called getInfo() in order to get the information that the form has already accepted from the user. Then, we will print the three components namely the name, degree and the age entered by the user and closing the window after that. Next, we will create another method called creatingForm() to create the main form in the window. For this form, we will create another layout and will start to add some rows for the three sections name, degree and the age of the user. Finally, we will st its layout and properties. Finally, we will introduce the main function and will create the PyQt5 application. We will then create an instance of the window and will display it on the screen using the show() method. Ultimately, we will start the application by executing the code. Complete code :Output : The output for the code of "Simple Registration Form using PyQt5 in Python" after implementation of the program is given below. Next TopicConditional Expressions in Python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India