How to create a GUI for a Python application using PyQt?

How-to-create-a-GUI-for-a-Python-application-using-PyQ

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 tools for clients.

We recently demonstrated the applications we built in Python to a prospective client. They were Okay with the demo, but we expect 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.

While analyzing how the demo underwent, our think-tank suggested creating a dedicated GUI for the tool. This aimed to let end users browse the input and output locations of their choice.

We found a few Python packages such as PySide, PyGTK, wxPython, Tkinter, and PyQt in the quest for a reliable Python package for building GUI. We tried getting well-versed using these packages but faced difficulty progressing due to the unavailability of documentation.

In all these packages, PyQt stood out and fulfilled our criteria. Hence, we decided to go ahead with PyQt. In 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. It 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.

Problem Statement

We wanted to create a simple GUI in Python that drives the back-end application upon accepting the input from the user.

Approach

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 to pass the input requirements to the back-end tool and let it run.

Implementation

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.

Demo Time

In addition to our efforts in creating GUI, we took an extra step, creating an 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 close the application when done!

Results

Our interface for clients has become more user-friendly, enhancing and revealing the true potential of our solution.

Finally, we would like to highlight that Python has rich packages that can resolve almost all project problems, making it a powerful and dynamic programming language.