mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
47 lines
1.6 KiB
HTML
47 lines
1.6 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
|
<title>Plugins</title>
|
|
<style>
|
|
mpy-script {
|
|
display: none;
|
|
}
|
|
</style>
|
|
<script type="importmap">
|
|
{ "imports": { "@pyscript/core": "../../core.js" } }
|
|
</script>
|
|
<script type="module">
|
|
import { define, whenDefined } from "@pyscript/core";
|
|
whenDefined("mpy").then(console.log);
|
|
define("mpy", {
|
|
interpreter: "micropython",
|
|
async onInterpreterReady(micropython, element) {
|
|
console.log(micropython);
|
|
// Somehow this doesn't work in MicroPython
|
|
micropython.io.stdout = (message) => {
|
|
console.log("🐍", micropython.type, message);
|
|
};
|
|
micropython.run(element.textContent);
|
|
element.replaceChildren("See console ->");
|
|
element.style.display = "block";
|
|
|
|
const button = document.createElement("button");
|
|
button.textContent = "click";
|
|
button.setAttribute("mpy-click", "test_click(event)");
|
|
document.body.append(button);
|
|
},
|
|
});
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<mpy-script mpy-click="test_click(event)">
|
|
def test_click(event):
|
|
print(event.type)
|
|
|
|
print('Hello Console!')
|
|
</mpy-script>
|
|
</body>
|
|
</html>
|