前言
使用 Python 创建上位机工具
- Python 3.10.10
- PySide 6.7.0
实现
项目组成
- main.qml
- main.py
文件
main.py
# This Python file uses the following encoding: utf-8
import sys
from pathlib import Path
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
qml_file = Path(__file__).resolve().parent / "main.qml"
engine.load(qml_file)
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
main.qml
import QtQuick.Window
Window {
width: 640
height: 320
visible: true
title: qsTr("Hello World")
}