How to convert a .ui file to .py file

SonicFancy picture SonicFancy · Mar 8, 2014 · Viewed 85k times · Source

This .ui file is made by Qt Designer. It's just a simple UI.

All the commands or codes for doing this on the websites I have looked through are not for windows.

Answer

ekhumoro picture ekhumoro · Mar 8, 2014

The pyuic tool works in exactly the same way on all platforms:

C:\>pyuic4 -h
Usage: pyuic4 [options] <ui-file>

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -p, --preview         show a preview of the UI instead of generating code
  -o FILE, --output=FILE
                        write generated code to FILE instead of stdout
  -x, --execute         generate extra code to test and display the class
  -d, --debug           show debug output
  -i N, --indent=N      set indent width to N spaces, tab if N is 0 [default: 4]
  -w, --pyqt3-wrapper   generate a PyQt v3 style wrapper

  Code generation options:
    --from-imports      generate imports relative to '.'
    --resource-suffix=SUFFIX
                        append SUFFIX to the basename of resource files
                        [default: _rc]

I suspect the reason "it doesn't work" is that the .ui file you are trying to convert is not in the current directory. So you need to cd to that directory first:

    C:\>cd C:\path\to\my\ui\files

then run pyuic:

    C:\path\to\my\ui\files\>pyuic4 -o ui_form.py form.ui