A PyScript egy keretrendszer, amit az Anaconda mutatott be, és lehetővé teszi Python scriptek futtatását HTML oldalon.
A PyScript WebAssembly-re fordul és egy kísérleti projekt.
Webhely
VSCode-hoz találunk „pysript” nevű kódot.
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script>
<!DOCTYPE html> <html lang="hu"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <py-script> print('Helló Világ!') </py-script> </body> </html>
<!DOCTYPE html> <html lang="hu"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>PyScript</title> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <div id="doboz"></div> <button py-click="msg()" id="gobutton">Mehet</button> <py-script> def msg(): doboz_div = Element("doboz") doboz_div.element.innerText = "Helló Világ" </py-script> </body> </html>
<!DOCTYPE html> <html lang="hu"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <div class="triangleForm"> <div class="mt-3"> <label for="base">Alap</label> <input type="text" value="30" id="base"> </div> <div class="mt-3"> <label for="base">Magasság</label> <input type="text" value="35" id="height"> </div> <div class="mt-3"> <button py-click="calcArea()">Számít</button> </div> <div class="mt-3"> <label for="area">Terület</label> <input type="text" id="area"> </div> </div> <py-script> def calcArea(): base = float(Element('base').value) height = float(Element('height').value) area = base * height / 2 Element('area').element.value =area </py-script> </body> </html>