39AndABit

radio_expt_v6-mpy.html

Nov 18th, 2023 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.       <meta charset="utf-8" />
  5.       <meta name="viewport" content="width=device-width,initial-scale=1" />
  6.       <title>Radio button expt v6 - 39AndABit 20231118</title>
  7.       <script type="module" src="https://pyscript.net/releases/2023.11.1/core.js"></script>
  8.   </head>
  9.   <body>
  10.     <input name="song" type="radio" id="baby_shark" mpy-change="song_radio_change" checked>
  11.     <label for="baby_shark">Baby Shark</label>
  12.     <br>
  13.     <input name="song" type="radio" id="nggyu" mpy-change="song_radio_change">
  14.     <label for="nggyu">NGGYU</label>
  15.     <br>
  16.    
  17.     <button mpy-click="announce_favourite">This is definitely my favourite choon</button>
  18.    
  19.     <div id="output"></div>
  20.    
  21.     <script type="mpy">
  22.         import sys
  23.         from pyscript import document
  24.        
  25.         outputElement = document.querySelector("#output")
  26.         outputElement.style["font-family"] = "monospace"
  27.         outputElement.innerText += f"{sys.version=}\n"
  28.        
  29.         favourite_song_id = "baby_shark"
  30.        
  31.         def song_radio_change(event):
  32.             global favourite_song_id
  33.             favourite_song_id = event.target.id
  34.        
  35.         def announce_favourite(event):
  36.             global outputElement
  37.             announce_text = f"Oh yes I really like {favourite_song_id} \u2764\uFE0F\n"
  38.             outputElement.innerText += announce_text
  39.     </script>
  40.   </body>
  41. </html>
  42.  
Advertisement
Add Comment
Please, Sign In to add comment