这个.ui文件由Qt Designer制作。这只是一个简单的用户界面。
在我查看过的网站上执行此操作的所有命令或代码都不适用于Windows。
pyuic工具在所有平台上以完全相同的方式工作:
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]
我怀疑“它不起作用”的原因是您尝试转换的.ui文件不在当前目录中。所以你需要先cd到那个目录:
C:\>cd C:\path\to\my\ui\files
然后运行pyuic:
C:\path\to\my\ui\files\>pyuic4 -o ui_form.py form.ui
在Windows中将.ui转换为.py
注意:此命令适用于python 3.4版本和PyQt4版本。如果您使用的是其他版本,则应更改数字(例如PyQt5)
Better Late Than Never,在Windows(.bat)上创建批处理文件并将以下内容粘贴到其中,从与文件相同的目录中保存并运行。
@echo off
title .UI to .py files converter !
echo Generate Python files from .UI files!
pause
echo ""
echo ""
echo ""
echo ""
echo UI file Name
set /p UiName=Enter .UI file Name:
echo ""
echo ""
echo ""
echo ""
echo PY file Name
set /p PyName=Enter .PY file Name:
echo ""
echo ""
echo ""
echo Start Converting Files Please wait.
call python -m PyQt5.uic.pyuic -x "%UiName%" -o "%PyName%"
echo QRC file Name
set /p QrName=Enter .qrc file Name:
echo ""
echo ""
echo ""
echo ""
echo PY file Name
set /p PiName=Enter .PY file Name:
echo ""
echo ""
echo ""
echo Start Converting Files Please wait.
pyrcc5 -o "%PiName%" "%QrName%"
echo Job Completed.
pause