Convert pyQt UI to python

237,426

Solution 1

You can use pyuic4 command on shell: pyuic4 input.ui -o output.py

Solution 2

For pyqt5 you can use

pyuic5 xyz.ui > xyz.py 

or

pyuic5 xyz.ui -o xyz.py

Solution 3

If you are using windows, the PyQt4 folder is not in the path by default, you have to go to it before trying to run it:

c:\Python27\Lib\site-packages\PyQt4\something> pyuic4.exe full/path/to/input.ui -o full/path/to/output.py

or call it using its full path

full/path/to/my/files> c:\Python27\Lib\site-packages\PyQt4\something\pyuic4.exe input.ui -o output.py

Solution 4

The question has already been answered, but if you are looking for a shortcut during development, including this at the top of your python script will save you some time but mostly let you forget about actually having to make the conversion.

import os #Used in Testing Script
os.system("pyuic4 -o outputFile.py inpuiFile.ui")

Solution 5

Quickest way to convert .ui to .py is from terminal:

pyuic4 -x input.ui -o output.py

Make sure you have pyqt4-dev-tools installed.

Share:
237,426
Shannon Hochkins
Author by

Shannon Hochkins

Passionate about learning new things, constantly working on my own projects to achieve that goal.

Updated on July 09, 2022

Comments

  • Shannon Hochkins
    Shannon Hochkins almost 2 years

    Is there a way to convert a ui formed with qtDesigner to a python version to use without having an extra file?

    I'm using Maya for this UI, and converting this UI file to a readable python version to implement would be really great!

  • Shannon Hochkins
    Shannon Hochkins almost 11 years
    How can I install pyuic4? It's saying 'pyuic4' is not recognized, I'm assuming I have to install it?
  • Frodon
    Frodon almost 11 years
    You must install Qt and PyQt (or Pyside) to have the pyuic4 tool which will convert your ui file to a Python file.
  • Shannon Hochkins
    Shannon Hochkins almost 11 years
    did you see my response?
  • Ben
    Ben over 9 years
    On some systems this may be called pyside-uic and be executable. BTW, yes, it would be run from the command line as it is used for any app development, not just Maya.
  • Tshilidzi Mudau
    Tshilidzi Mudau about 8 years
    I know this is an old question but in case anyone else is wondering, to install pyuic4 on Ubuntu: sudo apt-get install pyqt4-dev-tools qt4-designer
  • tarikki
    tarikki about 8 years
    Every time I use pyuic4, I have forgotten the syntax and come back here to check it, this must be the 15th time here during the past year...
  • Jeronimo
    Jeronimo almost 6 years
    If you're on Windows and don't have pyuic4 in your PATH, you can also use python.exe -m PyQt4.uic.pyuic input.ui -o output.py.
  • Mattu475
    Mattu475 almost 6 years
    what is the -x for?