Convert pyQt UI to python
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.
Shannon Hochkins
Passionate about learning new things, constantly working on my own projects to achieve that goal.
Updated on July 09, 2022Comments
-
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 almost 11 yearsHow can I install pyuic4? It's saying 'pyuic4' is not recognized, I'm assuming I have to install it?
-
Frodon almost 11 yearsYou must install Qt and PyQt (or Pyside) to have the
pyuic4
tool which will convert your ui file to a Python file. -
Shannon Hochkins almost 11 yearsdid you see my response?
-
Ben over 9 yearsOn 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 about 8 yearsI 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 about 8 yearsEvery 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 almost 6 yearsIf 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 almost 6 yearswhat is the -x for?