惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
U
Unit 42
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
G
Google Developers Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Jina AI
Jina AI
量子位
宝玉的分享
宝玉的分享
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
美团技术团队
The Hacker News
The Hacker News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tailwind CSS Blog
博客园 - 司徒正美
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Vercel News
Vercel News
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Privacy International News Feed
G
GRAHAM CLULEY
The Last Watchdog
The Last Watchdog
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
V2EX - 技术
V2EX - 技术

博客园 - 虚生

基于多模态声纹超声雷达温度气体的储能柜热失控智能监测预警系统特色解析 git删除推送到远程仓库的代码(git push 过) 基于多传感器融合(声闻,振动,超声,气体)的多模态智能安全卫士在哪些行业最容易落地? 储能行业安全监控的市场需求痛点有哪些呢? cursor使用技巧盘点 三轴传感器IIS3DWB适合的应用 场景有哪些? IIS3DWB性能指标总结 基于声波,超声波和振动传感器三位一体的多模态变电站出厂检测有市场吗? 基于声波,超声波和振动传感器三位一体的多模态变电站出厂检测市场前景 无人值守地面传感器(UGS)家族(T-UGS/CF UGS) 红外热像仪传感器MLX90640 应用场景简析 变电站感知层核心多物理量传感器简析 变压器数字化智能化浪潮中有哪些机遇以及目前的发展状况? 可穿戴设备和AI技术在临床CRO安全性监测中的应用案例 可穿戴设备和AI技术在临床CRO中的应用场景有哪些? 临床CRO对可穿戴设备以及AI技术的需求趋势 文本关键字搜索的本地离线开源大模型梳理 本地边缘计算的开源的本地工业声纹大模型推荐 字节 / 火山引擎的工业声纹基座使用说明 Deep Noise Suppression Mean Opinion Score (DNSMOS)含义解析 python中logger.info 打印多个变量值
main_window.ui 生成对应py文件的方法
虚生 · 2026-03-14 · via 博客园 - 虚生

main_window.ui 转成 .py,最常用、最稳定的是命令行工具(pyuic5 / pyside6-uic),也可以用 IDE 插件一键转换。


一、先安装对应工具(二选一)

1. PyQt5(最常用)

pip install pyqt5 pyqt5-tools

转换命令:pyuic5

2. PySide6(Qt 官方)

转换命令:pyside6-uic


二、命令行转换(最推荐)

1. 进入 main_window.ui 所在目录

cd /path/to/your/ui/folder

2. 执行转换(二选一)

  • PyQt5:
pyuic5 main_window.ui -o main_window.py
  • PySide6:
pyside6-uic main_window.ui -o main_window.py
  • -x 可让生成的 .py 直接运行(含测试入口):
pyuic5 -x main_window.ui -o main_window.py

三、VSCode 一键转换(插件)

  1. 安装插件:Qt for Python(作者:Sean)
  2. 右键点击 main_window.ui → Compile UI to Python
  3. 自动生成 main_window.py 到同目录。

四、生成后如何使用

# main.py
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from main_window import Ui_MainWindow  # 导入生成的UI类

class MyWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)  # 加载UI

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MyWindow()
    win.show()
    sys.exit(app.exec_())

五、常见问题

  • 'pyuic5' 不是内部命令
    • Windows:把 Python/Scripts 加入系统 PATH
    • Linux/macOS:pip install pyqt5-tools 或用 python -m PyQt5.uic.pyuic
  • 每次改 .ui 都要重新执行转换命令。