pyqt簡單介紹和使用

QML和PyQT5聯合編程python

安裝pyqt編程

pip3 install PyQT5app

main.QMLui

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1

ApplicationWindow{
    visible:true
    width:640
    height:480
    id:window
    title: "editor"

    signal textUpdated(string text)


    TextArea{
        text:"hello"
        onTextChanged: textUpdated(text);
    }

}

有了QML文件以後,咱們就能夠根據該文件進行python文件的編寫,把裏面的信號傳遞給python文件中spa

mian.pycode

import sys
from PyQt5.QtCore import QObject, QUrl, Qt
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine

def show(text):
print(text)


if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load('main.qml')
win = engine.rootObjects()[0]
win.textUpdated.connect(show)
win.show()
sys.exit(app.exec_())

這樣,一個簡單的python和Qml文件的通訊的例子就完成了。blog

相關文章
相關標籤/搜索