似乎初始化 brython 需要这样做:
<body onload="brython()">
在链接了 brython.js 之后,我尝试在另一个 js 中调用 brython() ,<script>
但它似乎没有被调用。
当我最终自己在浏览器控制台中调用 brython 时,它调用了 brython,甚至执行了我的 python 代码。
为了给出一个不起作用的完整例子,这里有一个例子。我可能缺乏一些关于如何以及何时编译和执行 javascript 的基本知识......
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/js/brython.js"></script>
</head>
<!-- <body onload="brython()"> -->
<body>
<script type="text/javascript">
console.log("calling brython() here");
brython();
console.log("I just called brython()");
</script>
<script type="text/python">
from browser import document, alert
def echo(*args):
alert("Hello {} !".format(document["zone"].value))
document["test"].bind("click", echo)
print("what")
</script>
<p>Your name is : <input id="zone" autocomplete="off">
<button id="test">clic !</button>
</body>
</html>