Skip to content

Events are only working when passed an argument #203

@berinhard

Description

@berinhard

Event handler functions such as keyPressed or mouseDragged from p5.js doesn't require any parameter to work. But pyp5js is only working if the event paremeter is present in the function definition.

So, for example, running the following code with the demo editor raises an TypeError as the traceback describes:

Sample code

def setup():
    createCanvas(200, 200)

def draw():
    background(200)
    diameter = sin(frameCount / 60) * 50 + 50
    fill("blue")
    ellipse(100, 100, diameter, diameter)

def keyPressed():
    print(key)

Traceback error

Uncaught PythonError: Traceback (most recent call last):
  File "<exec>", line 1595, in wrapper
  File "<exec>", line 1583, in pre_draw
TypeError: keyPressed() takes 0 positional arguments but 1 was given

But, if we change the keyPressed to receive an argument, it works. So, the pyodide mode must be updated to not require this parameter in order for event functions to work.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions