# Simple python class wont render Invoking \<bound method Sketch.on\_timer of Sketch\> (p5py)

**URL:** https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959
**Category:** Processing.py
**Created:** [May 17, 2020, 9:35am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959 "2020-05-17T09:35:10Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 17, 2020, 9:35am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/1 "2020-05-17T09:35:10Z")

</div>

I’m trying to make a simple class.

```auto

class class_circle:
    def __init__ (self, r):
        self.r = r

    def show(self):
        fill(255)
        circle(0,0,self.r)

c = class_circle(100)

def setup():
    size(1280, 720)

def draw():
    background(0)
    c.show()

run()

```

but i get the error

```auto
ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x7f0e8d6757d0>> for Event

```

not sure what happened, I tried finding another example online and I got the same error. Would very much appreciate your help 😃

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [May 17, 2020, 9:46am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/2 "2020-05-17T09:46:24Z")

</div>

Hi,

Is there the same error with a simple program (without any class, only with setup and draw)?

What is the function `run()` ?

---

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 17, 2020, 10:09am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/3 "2020-05-17T10:09:12Z")

</div>

thanks for helping me out josephh.  
The function run is from p5. I guess it calls setup and then runs the draw loop. nothing happens without the run command.

Brilliant suggestion for fixing the error. I thought I’ve checked everything but I forgot the position should be a vector.

So in the show() method this fixed my error:  
circle(0,0,self.r) --\> circle((0,0),self.r)

So this is the full working class:

```auto
class class_circle:
    def __init__ (self, r):
        self.r = r

    def show(self):
        fill(255)
        circle((0,0),self.r)

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [May 17, 2020, 10:35am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/4 "2020-05-17T10:35:59Z")

</div>

I just realised that your code is working fine on my machine using Processing.py

Reading the documentation for the `circle()` function, the first two parameters are the x and y location, it’s not a tuple : [https://py.processing.org/reference/circle.html](https://py.processing.org/reference/circle.html)

You are using Processing.py right? It seems that there is no need for a `run()` function, it’s not in the reference or in any tutorials :

- [https://py.processing.org/reference/](https://py.processing.org/reference/)
- [https://py.processing.org/tutorials/gettingstarted/](https://py.processing.org/tutorials/gettingstarted/)

---

<div class="post-metadata">

### Author: ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)
#### Post date: [May 17, 2020, 10:50am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/5 "2020-05-17T10:50:54Z")

</div>

For [p5](https://p5.readthedocs.io/en/latest/index.html), you must use a tuple for your x-y coordinates:

```auto
circle((0, 0), self.r)

```

---

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 17, 2020, 11:34am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/6 "2020-05-17T11:34:50Z")

</div>

ty @josephh. I’m usig [p5py](https://github.com/p5py/p5). As I understood proccesing.py is only python2.7 doesn’t let me import whatever python package I want in my own editor.

@tabreturn ty. If I ever learn how to contribute to a package I would love to make pyp5 return an error code like “First index should be tuple, not scalar”

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 19, 2020, 9:53pm UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/7 "2020-05-19T21:53:54Z")

</div>

> [@renec112](#):
>
> If I ever learn how to contribute to a package I would love to make pyp5 return an error code like “First index should be tuple, not scalar”

@villares is actually looking at possibly creating API wrapper or fork to address these kinds of mismatches. See: [API compatibility for p5py](https://discourse.processing.org/t/api-compatibility-for-p5py/20492)

---

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 26, 2020, 9:09am UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/8 "2020-05-26T09:09:37Z")

</div>

Than you for this solution @jeremydouglass. I’m new to devloping python packages. Why not add these helpful error message in the main package? To me it seems helpful - but I would love to know what an experienced developer thinks

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 26, 2020, 12:38pm UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/9 "2020-05-26T12:38:49Z")

</div>

> [@renec112](#):
>
> Why not add these helpful error message in the main package?

It would be helpful, I agree! The only reason I can think of not to would be if the extra error handling incurred a performance hit – or if the method could be made smarter by handling non-tuple arguments correctly in line with the other APIs, in which case that error message would no longer make sense.

There is currently a proposal to do that here:

> <https://github.com/p5py/p5/pull/169>
>
> This PR addresses #130 and is a work-in-progress. Feel free to comment if you ha…ve any suggestions!
> 
> In short, this PR will enable p5py to support non-tuple arguments in functions that have counterparts in the standard Python Mode of Processing.
> 
> \### Implementation
> I plan to use if statements to check the number of parameters being passed in.
> For example:
> \`\`\`python
> def line(\*args):
> if len(args) == 2:
> p1, p2 = args\[0\], args\[1\]
> elif len(args) == 4:
> p1, p2 = args\[:2\], args\[2:\]
> elif len(args) == 6:
> p1, p2 = args\[:3\], args\[3:\]
> else:
> raise ValueError("Unexpected number of arguments passed to line()")
>         
> \<Rest of existing code\>
> ...
> \`\`\`
> Another more elaborate example with error checking
> \`\`\`python
> from collections import Iterable
> 
> def line(\*args):
> if len(args) \< 2:
> # Not enough arguments are passed 
> raise ValueError("Invalid number of args to line; expected more than 2")
> elif not isinstance(args\[0\], Iterable):
> if len(args) == 4: # 2D
> p1, p2 = args\[:2\], args\[2:\]
> elif len(args) == 6: # 3D
> p1, p2 = args\[:3\], args\[3:\]
> else:
> raise ValueError("Invalid nubmer of args to line; expected 4 or 6 arguments when first argument is not an iterable")
> else:
> assert len(args) == 2, "Invalid number of args to line; expected two iterables when first element is an iterable"
>     
> \<Rest of existing code\>
> ...
> \`\`\`
> I am leaning towards the simple version because
> 1. It is cleaner
> 2. The code will fail later anyway if incorrect parameters are passed in
> 
> A con to the simple approach is that the error messages can be more cryptic if we rely on later functions to check the parameters for us. Therefore, which version to use is open for discussion.
> 
> \### Documentation Changes
> Add a section under each function to document new API calls as well as old ones explicitly. I found the format in the Proccesing Language Docs to be helpful.
> 
> Example: https://processing.org/reference/line\_.html
> Rendered in p5py docs:
> \<img src="https://user-images.githubusercontent.com/18119047/82772768-100c2080-9df5-11ea-8f95-07144df49546.png" width="400px" /\>
> 
> \### Functions to be changed
> \`\`shape.py\`\`
> 
> \- \[x\] p5.line()
> \- \[x\] p5.ellipse()
> \- \[x\] p5.circle()
> \- \[x\] p5.arc()
> \- \[x\] p5.triangle()
> \- \[x\] p5.quad()
> \- \[x\] p5.rect()
> \- \[x\] p5.square()
> \- \[x\] p5.bezier()
> \- \[x\] p5.bezier\_point()
> \- \[x\] p5.bezier\_tangent()
> \- \[x\] p5.curve()
> \- \[x\] p5.curve\_point()
> \- \[x\] p5.curve\_tangent()
> \- \[x\] p5.quadratic\_point()
> 
> \`\`transforms.py\`\`
> \- \[x\] p5.camera()
> 
> \`\`image.py\`\`
> \- \[x\] p5.image()
> 
> \`\`font.py\`\`
> \- \[x\] p5.text()

**edit**

But you could also open a PR with proposed error messages instead / in the meantime / as well.

---

<div class="post-metadata">

### Author: ![renec112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/renec112/32/9168_2.png) [@renec112](https://discourse.processing.org/u/renec112)
#### Post date: [May 26, 2020, 1:35pm UTC](https://discourse.processing.org/t/simple-python-class-wont-render-invoking-bound-method-sketch-on-timer-of-sketch-p5py/20959/10 "2020-05-26T13:35:50Z")

</div>

I see - Thank you 🙂
