0

Here is my HTML code:

<!DOCTYPE html>
<html lang="en" class="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ScratchFind</title>
    <link rel="stylesheet" href="style.css">
    <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>
    <script type="py" src="./main.py" config="./pyscript.json"></script>
</head>
<body>
    <!-- Back end -->
    <script src="script.js"></script>
    
    <!-- Front end -->
    <h1>ScratchFind</h1>
    <input id="url" type="text" name="input" placeholder="Paste your URL here">
    <input py-click="hello" type="submit" value="Find!">
    <h1 id="display"></h1>
    
    <!-- Theme toggle -->
    <label class="switch">
        <input type="checkbox" onclick="toggleTheme()">
        <span class="slider"></span>
    </label>

</body>
</html>

and here is my python code:

import requests
from pyscript import document

url = document.querySelector("#url")
display = document.querySelector("#display")
display.innerText = "a"
link = ""

def hello():
  link = url.value
  display.innerText = link

main.py is working but the function isn't called when I click the button.

I am expecting that when the button is pressed the code inside the function hello works.

1 Answer 1

1

When I try your code, I see an error:

TypeError: hello() takes 0 positional arguments but 1 was given

When using the py-*event syntax, the function is passed an Event object corresponding to the triggering event. You can either receive this event and use it (def hello(evt):) or swallow and ignore it (def hello(*args)).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.