Last active
December 5, 2017 13:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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