Creating a Qt Designer GUI and linking it to Python code

I was experimenting with WinPython and Qt Designer which comes with it.  It looks like a great way to build a Windows GUI and link Python code to it.

The normal procedure is to create a .ui file with Qt Designer, then run pyuic.py to convert it to a Python Windows form.  When you run the .py file which results, your GUI appears.

Next you need to add code behind your GUI to make it functional, but you don’t want to modify the .py created by pyuic because when you modify your GUI it will be overwritten.  How should you make an independent link between your GUI and the code behind it?

A solution from stackoverflow is to add GUI creation code to your Python program, and link actions and I/O from the GUI to the program.

A complete example is in PythonGuiLinkExample.zip. The general procedure is this:

  1. Define/modify the GUI GuiLinkExample.ui using Qt Designer.
  2. Run custom batch file GuiLinkExampleRebuild.bat to convert this .ui to .py as required.
  3. Create/modify GuiLinkExampleMain.py, which includes your main logic and links to the GUI (see source code for details).
  4. Run GuiLinkExampleMain.py directly from Windows (no Python shell required).

Repeat steps 1 and 2 to modify the GUI. Repeat step 3 to add or change the logic behind the GUI.