python - 如何将 .ui 文件转换为 .py 文件

标签 python user-interface pyqt qt-designer

这个 .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

关于python - 如何将 .ui 文件转换为 .py 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22266802/

相关文章:

python - **SQLAlchemy** :Get a count of one column where another column is distinct

ios - 在ios中的屏幕方向期间调整轮播 View 的大小

Java - 水平重复渐变图像(Swing)

javascript - 获得焦点时选择文本框的所有内容(Vanilla JS 或 jQuery)

python - 代理背后的 PyQt + QtWebkit

python - 命令行脚本的 Cookbook GUI 界面

python - 如何在 python 3 中使用 urllib 请求解决 SSL 握手失败?

python - 在Python中写入文件

python - 在突变中传递链接数组 [graphene/python/graphql]

windows - Windows下使用PyQt的Webkit无法通过xhr获取远程资源