Pyodide with PyQt5
This is not a standard pyodide package: PyQt5 is built statically into main pyodide module. For now Qt cannot be built as shared library (see QTBUG-63925).
- Install Docker
./run_dockerpip install sippip install PyQt-buildermake
example.py - PyQt application:
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
qbtn = QPushButton('Quit', self)
qbtn.clicked.connect(QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(50, 50)
self.setWindowTitle('Quit button')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
#do not call "app.exec_()" hereHTML page:
<!doctype html>
<html>
<head>
</head>
<body>
<!-- pyqt application will be shown on this canvas -->
<canvas id="qtcanvas" oncontextmenu="event.preventDefault()" contenteditable="true"></canvas>
<script type="text/javascript">
async function main(){
let indexURL = "./";
var canvas = document.querySelector('#qtcanvas');
const { loadPyodide } = await import(indexURL + "pyodide.mjs");
// to facilitate debugging
globalThis.loadPyodide = loadPyodide;
globalThis.pyodide = await loadPyodide({
canvasElements : [canvas],
});
// load our pyqt application
pyodide.runPython(await (await fetch("./example.py")).text());
// QApplication.exec() cannot be called from python code, so call it from JS here
pyodide.execQApplication();
}
main();
</script>
</body>
</html>