title: How to find the center point of a widget/object and use it in another function
body: <p>what I have here is work-in-progress of my Towers of Hanoi puzzle game. I've only been working on it a day or two and a problem I have here is the following: How am I able to snap an object to a specific position on the screen. What happens at the moment is the object snaps to a specific position depending on where your mouse touches the object.</p>
  
  <pre><code>import Tkinter as tk
  from Tkinter import *
  class SampleApp(tk.Tk):
      User_Input = input("How many disks?")
      global User_Input
      '''Illustrate how to drag items on a Tkinter canvas'''
  
      def __init__(self, *args, **kwargs):
  
  
          tk.Tk.__init__(self, *args, **kwargs)
  
          # create a canvas
          self.canvas = tk.Canvas(width=600, height=600)
          self.canvas.pack(fill="both", expand=True)
  
          # this data is used to keep track of an
          # item being dragged
          self._drag_data = {"x": 0, "y": 0, "item": None, "score": 0}
          self._disk_data = {"x": 0, "y": 0}
          self._pole1_data = {"x": 102, "y": 425}
          self._pole2_data = {"x": 0, "y": 0}
          self._pole3_data = {"x": 0, "y": 0}
  
          # create a couple movable OBJECTS
  
          self._create_token((100, 550), "black")
          self._create_bases((100, 600), "orange")
          self._create_poles((145, 585), "blue")
          self.scores(0)
  
          # add bindings for clicking, dragging and releasing over
          # any object with the "token" tag
          self.canvas.tag_bind("token", "&lt;ButtonPress-1&gt;", self.OnTokenButtonPress)
          self.canvas.tag_bind("token", "&lt;ButtonRelease-1&gt;", self.OnTokenButtonRelease)
          self.canvas.tag_bind("token", "&lt;B1-Motion&gt;", self.OnTokenMotion)
  
      def scores(self, score):
          global setrep
          global score_set
          if score &gt;= 0:
              self.score_set = Label(self.canvas, text = "Moves: " + str(score), width = 20, height = 5, bg = "black", fg = "white").place(relx = 0.76, rely = 0.82)
  
  
      def _create_poles(self, coord, color):
          (x,y) = coord
          for i in range(0, 3):
              self.canvas.create_rectangle(x-45, y-30, x-45, y-395, outline = color, fill = color)
              x += 150
  
      def _create_bases(self, coord, color):
          (x,y) = coord
          for i in range(0, 3):
              self.canvas.create_rectangle(x-45, y-25, x+45, y-45, outline = color, fill = color)
              x += 150
  
  
  
      def _create_token(self, coord, color):
          '''Create a token at the given coordinate in the given color'''
          (x,y) = coord
          for i in range(0, User_Input):
  
              self.canvas.create_rectangle(x-45+(8*i), y-25, x+45, y-45, outline=color, fill=color, tags="token")
              y -= 50
              x -= 4.5
  
      def OnTokenButtonPress(self, event):
          '''Being drag of an object'''
          # record the item and its location
          self._drag_data["item"] = self.canvas.find_closest(event.x, event.y)[0]
          self._drag_data["x"] = event.x
          self._drag_data["y"] = event.y
  
      def OnTokenButtonRelease(self, event):
          '''End drag of an object'''
          # reset the drag information
          self._drag_data["x"] = 0
          self._drag_data["y"] = 0
          self._drag_data["score"] += 1
          self.scores(self._drag_data["score"])
          self.canvas.move(self._drag_data["item"], self._pole1_data["x"]-event.x, self._pole1_data["y"]-event.y)
          print event.x, event.y
          self._drag_data["item"] = None
  
  
      def OnTokenMotion(self, event):
          '''Handle dragging of an object'''
          # compute how much this object has moved
          delta_x = event.x - self._drag_data["x"]
          delta_y = event.y - self._drag_data["y"]
          # move the object the appropriate amount
          self.canvas.move(self._drag_data["item"], delta_x, delta_y)
          # record the new position
          self._drag_data["x"] = event.x
          self._drag_data["y"] = event.y
  
  if __name__ == "__main__":
      app = SampleApp()
      app.mainloop()
  </code></pre>
  
  <p>I advise just using 1 or 2 disks for testing as it may get confusing otherwise.</p>
  
  <p>The main part you wan to be looking at is in <strong>def TokenButtonRelease(self, event)</strong> and where it states <strong>self.canvas.move(self._drag_data["item"], self._pole1_data["x"]-event.x, self._pole1_data["y"]-event.y)</strong></p>
  
  <p>The problem is the "-event.x" and "-event.y", as I really want to be minus'ing the centre point of the object. So my main question is how do I find this and how do I state that I want this to be the value that has to be taken away. You will notice that the object snaps to a certain position, but if you grab the object at different points, it will obviously snap to a slightly different point.</p>