title: How reference back a paint event on Python Canvas using Tkinter?
body: <p>I know this is probably the simplest question ever. However, I'm getting started on learning Tkinter and I don't know how to reference back the event for when a mouse click takes place on the GUI. </p>
  
  <p>I want to draw some points when I click on the canvas. I cannot reference back the canvas variable in the paint function.</p>
  
  <p>This piece of code is based on the question here in <a href="https://stackoverflow.com/questions/39888580/how-can-i-draw-a-point-with-canvas-in-tkinter">SO</a> </p>
  
  <p>Whenever I attempt the example I get an error in the paint function that says</p>
  
  <blockquote>
    <p>NameError: name 'canvas' is not defined;  </p>
  </blockquote>
  
  <pre><code>def main():
      master = Tk()
      # Right side of the screen / img holder
      right_frame = Frame(master, width=500, height=500, cursor="dot")
      right_frame.pack(side=LEFT)
  
      # Retrieve image
      image = Image.open("./image/demo.JPG")
      image = image.resize((800, 700), Image.ANTIALIAS)
      photo = ImageTk.PhotoImage(image)
  
      # Create canvas
      canvas = Canvas(right_frame, width=800, height=700)
      canvas.create_image(0, 0, image=photo, anchor="nw")
      canvas.pack()
      canvas.bind("&lt;B1-Motion&gt;", paint)
      message = Label(right_frame, text="Press the mouse to draw")
      message.pack(side=BOTTOM)
  
  
      mainloop()
  
  
  def paint(event):
      python_green = "#476042"
      x1, y1 = (event.x - 1), (event.y - 1)
      x2, y2 = (event.x + 1), (event.y + 1)
      canvas.create_oval(x1, y1, x2, y2, fill=python_green)
  
  
  if __name__ == "__main__":
      main()
  </code></pre>