title: Detecting when two objects are overlapping each other in tkinter
body: <p>I'm working on a snake game and I'm trying to figure out how to get the program to detect when 2 objects are overlapping each other. I tried using using <code>canvas.find_overlapping</code>, but it only works when I run my code.</p>
  <p>Here is my code below:</p>
  <pre><code>from tkinter import *
  import time
  import random
  
  class snake:
      def __init__(self):
         self.apple = canvas.create_rectangle(70+100, 70+100, 100+100, 100+100, fill=&quot;red&quot;)
         self.snake = canvas.create_rectangle(50,50,100,100,fill=&quot;white&quot;,outline= &quot;white&quot;)
         canvas.bind_all('&lt;Left&gt;', self.Left)
         canvas.bind_all('&lt;Right&gt;',self.Right)
         canvas.bind_all('&lt;Up&gt;', self.Up)
         canvas.bind_all('&lt;Down&gt;', self.Down)
         pos = canvas.coords(self.snake)
         if canvas.find_overlapping(pos[0], pos[1], pos[2], pos[3] &gt;= (self.apple)):
             canvas.move(self.apple, random.randint(0, 750), random.randint(0, 850))
  
      def Left(self, event):
          if event.keysym == 'Left':
              canvas.move(self.snake, -20, 0)
      def Right(self, event):
          if event.keysym == 'Right':
              canvas.move(self.snake, 20, 0)
      def Up(self, event):
          if event.keysym == 'Up':
              canvas.move(self.snake, 0, -20)
      def Down(self,event):
          if event.keysym == 'Down':
              canvas.move(self.snake,0,20)
  
  
  tk =Tk()
  canvas=Canvas(tk,width=800,height=900,bg= &quot;lightblue&quot;)
  
  Snake = snake()
  while True:
      time.sleep(1/60)
      canvas.pack()
      canvas.mainloop()
  </code></pre>