How to create GUI for Python application using PyQt?
At Ellicium, we have built diverse Python tools while working on client projects. We strive to outperform ourselves every time. Continuous improvement is the key! So here is a story of how we enhanced one of the Python tool for client.
Recently, we demonstrate the applications that we built in Python to a prospective client. They were Okay with the demo but we are expecting more than Okay feedback. Like every other tool, our python tool requires input and output paths to access and store the data. The tool accepts the dedicated static folders (created once) for input and output locations. In the process of analysing how the demo underwent, our think-tank suggested to create a dedicated GUI for the tool. Aim of this was to let end user browse the input and output locations of their choice.
In the quest for a reliable Python package for building GUI, we found few python packages such as PySide, PyGTK, wxPython, Tkinter, PyQt. We tried getting well versed using these packages but faced difficulty in progressing due to un-availability of documentation.
In all these packages PyQt stood out and fulfilled our criteria. Hence, we decided to go ahead with PyQt. At the end, it helped us to resolve all issues.
Prologue on PyQt:
- PyQt is a Python wrapper for Qt software which is a GUI tool kit
- PyQt provides several functionalities to develop the GUI windows
- PyQt does not come with python installation. Needs to be installed separately
- PyQt is free
I can’t hold myself back from explaining the power of Python in creating the GUI windows. Here is the real-time use case to make you understand better.
We wanted to create a simple GUI in Python that drives the back-end application upon accepting the input from the user.
We decided upon the following approach for this:
- First build the GUI that facilitates browsing the i/o locations.
- Upon clicking the submit button, a batch script will be triggered that will pass the input requirements to the back-end tool and let it run.
As per the decided approach, we developed the GUI in PyQt. Below is the screenshot of the same. This GUI takes inputs from the user. Upon clicking the submit button, the back-end tool runs.
For more details about implementation, you could comment below and I feel happy to answer all your queries.
In addition to our efforts put in creating GUI, we took an extra step creating exe (executable) file in Python for the entire application. A simple double click would kick start the application, prompt the user for inputs, trigger the execution and closes the application when done!
Our interface for client has become more user friendly, enhancing and revealing true potential of our solution.
Finally, we would like to highlight that Python has rich packages which can be used to resolve almost all project problems, making it powerful and dynamic programming language.