< Web

PyScript

Szerző: Sallai András

Copyright © 2023, Sallai András

Szerkesztve: 2023

Licenc: CC BY-SA 4.0

Web: https://szit.hu

Bevezetés

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.

Webhely

https://pyscript.net/ (2023)

Beállítás

<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script>

Helló Világ

<!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>

Kattintás

<!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>

Háromszög területe

<!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>