title: How to use a canvas parameter in a __init__ function of a class?
body: <p>I made this module called gamesmodule, and I am working on a program that makes a ball spawn and bounce in the canvas. I used a</p>
  
  <pre><code>class Ball:
      def __init__(self, canvas):
          self.canvas = canvas
          self.id = canvas.create_oval(10, 10, 25, 25, fill='red')
          self.canvas.move(self.id, 25, 25)
          self.x = 0
          self.y = -1
          self.canvas_height = self.canvas.winfo_height
          self.canvas_width = self.canvas.winfo_width
  </code></pre>
  
  <p>and the init function contained a canvas parameter, which to enter a canvas name. I had predefined the canvas, and created the ball in the class:</p>
  
  <pre><code>ball = Ball(canvas)
  </code></pre>
  
  <p>but the Python shell outputted this error:</p>
  
  <pre><code> Traceback (most recent call last):
   File "&lt;pyshell#59&gt;", line 1, in &lt;module&gt;
   ball = Ball(canvas)
   NameError: name 'canvas' is not defined
  </code></pre>