-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Labels
Milestone
Description
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.