Chrome 如何在PyScript中使用输入?

7ivaypg9  于 2023-04-27  发布在  Go
关注(0)|答案(1)|浏览(94)

当我在google chrome上打开它们时,基本的python输入代码无法正常工作。是否有不同的是用PyScript编写代码,这仍然和正常的输入一样简单?我真的不想把所有东西都转换为JavaScript,主要是因为我需要学习JavaScript是如何工作的。(也很抱歉我只是使用记事本的格式)

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

<body>

<py-script>

print("welcome to madlibs!")
print('please do not put any spaces in your answers')
print("")
print("")
print("")
name1 = input('name?')

this is what happens when I open it on google chrome.它甚至不会让页面加载,直到它有输入。
我希望它能像在python中那样运行,但在进一步的google搜索中我发现这是不可能的,我以为至少它会把问题放在输入框中,但它也没有做到。

nqwrtyyt

nqwrtyyt1#

你需要一个浏览器感知程序。

<html>

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

<body>
  welcome to madlibs!<br>
  please do not put any spaces in your answers'<br><br><br><br>
  <button id="button">Input</button>
  name = <span id="span"></span>
  <py-script>
    import js
    from pyodide.ffi import create_proxy

    def input_name(event):
      name = input()
      js.document.getElementById("span").innerText = name

    proxy = create_proxy(input_name)
    js.document.getElementById("button").addEventListener("click", proxy)
  </py-script>
</body>

</html>

相关问题