<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>🦜 Polyglot - Piratical PyScript</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2024.4.1/core.css">
<script type="module" src="https://pyscript.net/releases/2024.4.1/core.js"></script>
</head>
<body>
<!-- TODO: Fill in our custom application code here... -->
<button id="myButton">点击我!</button>
<script type="mpy">
# 导入所需的模块
from pyscript import document, window
# 定义回调函数
def handle_click(event):
window.alert("按钮被点击了!")
# 获取要监听的元素
button = document.getElementById("myButton")
# 在按钮上添加点击事件的监听器
button.addEventListener("click", handle_click)
</script>
</body>
</html>
|