DEV Community

Jason Cruz
Jason Cruz

Posted on

Write Dynamically with Python & PyQt5

It can be a lot easier doing it this way

Quick Tutorial

Assuming you already know how to use the QT Designer program that can be easily installed using pip. Creating a dynamic file shouldnt be that hard to make, for me it was. I searched high and low for 2.5 days until I randomly found an interesting site that had a set by step way to try creating a dynamic python file using your interface.ui file you get when you save your design inside Qt Designer.


2 Important Things

When working with Qt Designer, after saving your work, it will be saved inside a UI & QRC file. My old way of doing things was once I converted my interface.ui file to interface.py file, I forgot my icons, because with Qt Designer and python, those are not imported for you. I struggled for days on this issue.

Real quick.

You must import your resource file (resources.qrc) also to a python file. Using this command:

pyrcc5 resources.qrc -o resources.py

Once you have created your python file, you wil want to import it into your dynamic file you are creating. As example below:

Image description

Main.py

Or whatever you would like to call that file, this file will run your new python file, and from here you can make all the corrections to the mechanics of your program while the UI is the skeleton mode in a different file. This is helpful when you have to make changes to your UI file, this way you wont be overwriting your code that you wrote over and over again.


Hope that helps!

Top comments (1)

Collapse
 
naucode profile image
Al - Naucode

Thanks, it was a good read, bookmarked, and followed!