Skip to content

Instantly share code, notes, and snippets.

@kikocorreoso
Last active December 5, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikocorreoso/4be9df5f2c419fe777db857567592c1a to your computer and use it in GitHub Desktop.
Save kikocorreoso/4be9df5f2c419fe777db857567592c1a to your computer and use it in GitHub Desktop.
Brython app embedded in PyQt5. Save all the files on the same folder and run main.py
<!DOCTYPE html>
<html><head>
<meta name="description" content="Brython">
<meta name="keywords" content="Python,Brython">
<meta name="author" content="Pierre Quentel">
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<noscript>Please enable Javascript to view this page correctly.</noscript>
<script type="text/javascript" src="brython.js"></script>
<script type="text/python3">
from browser import alert, document
def fn(ev):
alert("Hola mundo")
document["btn"].bind("click", fn)
</script>
<body onload="brython({debug:1, cache:'none'})">
<div id="content">
<button id="btn">click!!</button>
</div>
</body>
</html>
import sys
import os
from PyQt5.QtWidgets import (
QApplication,
QVBoxLayout,
QWidget
)
from PyQt5.QtCore import QUrl
from PyQt5.QtWebKitWidgets import QWebView
class Window(QWidget):
def __init__(self):
super().__init__()
self._setup()
def _setup(self):
# setup main window
self.setGeometry(100, 100, 600, 400)
self.setWindowTitle('Hola mundo')
# show main window
self.show()
# Layout
main_layout = QVBoxLayout()
webv = QWebView()
localpath = os.path.dirname(os.path.abspath(__file__))
url = os.path.join(localpath, "index.html")
webv.load(QUrl.fromLocalFile(url))
main_layout.addWidget(webv)
self.setLayout(main_layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Window()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment