title: Using a tkinter Canvas to display an image then drawing on the image using cv2.circle/cv2.line
body: <p>I am relatively new to Python and I am trying to build a GUI using <code>tkinter</code>, utilising the features of <code>cv2</code>.</p>
  <p>I wish to bring in an image (<code>tk.Canvas</code> currently used to display), use an <code>tk.Entry</code> box to create a list of components from the user, create radio buttons from the users inputs and then draw circles on the image using mouse clicks, each component in a different colour.</p>
  <p>So far I have successfully created the <code>tkinter</code> window that does all of the above apart from draw on the image. I have a separate code that I initially created to draw the <code>cv2.circles</code> onto a JPEG that works fine, I just do not know how to link the tkinter GUI to the <code>cv2</code> library.</p>
  <p>Any help would be greatly appreciated as I cannot find anything asking the same question. I have attached part of the code below...</p>
  <p>Best,
  George</p>
  <p><strong>The function for selecting the file path, importing the image, and displaying it on a canvas:</strong></p>
  <pre><code>    def selecting_file(self):
      self.file_path = filedialog.askopenfilename()
  
      self.cv_img = cv2.cvtColor(cv2.imread(self.file_path), cv2.COLOR_BGR2RGB)
      self.height, self.width, self.no_channels = self.cv_img.shape
  
  
      self.canvas = tk.Canvas(self.window, width=self.width, height=self.height)
      self.canvas.pack()
  
      self.photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(self.cv_img))
  
      self.canvas.create_image(0, 0, image=self.photo, anchor=tk.NW)
      self.label = tk.Label(image=self.photo)
      self.label.image = self.photo
  </code></pre>
  <p><strong>The functions for creating the radio buttons and then obtaining the values from them:</strong></p>
  <pre><code>    def compile_radio(self):
      self.v = tk.StringVar()
      for i in App.part_list:
          self.radio = tk.Radiobutton(self.window, text=i, variable=self.v, value=App.part_list.index(i)+1, command=self.radio_select)
          self.radio.pack()
  
  val = 0
  def radio_select(self):
      self.radio_value = self.v.get()
      self.radio_value = App.val
  </code></pre>
  <p><strong>The function and code that is not within this script that allows to draw the circles onto a cv2.imshow:</strong></p>
  <pre><code>def draw_circle1(event, x, y, flags, param):
  if event == cv2.EVENT_LBUTTONDOWN:
      cv2.circle(img, center = (x, y), radius = 5, color = (0,0,255), thickness = 2)
      global red_count
      red_count += 1
  
  img = cv2.imread('IMAGE.jpg')
  cv2.namedWindow(winname = 'Drawing')
  cv2.setMouseCallback('Drawing', draw_circle1)
  
  while True:
      cv2.imshow('Drawing',img)
      if cv2.waitKey(10) &amp; 0xFF == 27:
          break
  cv2.destroyAllWindows()
  </code></pre>