title: How to swap widget placement in a tkinter grid using drag and drop?
body: <p>I am trying to swap the placement of two widget in a grid layout in tkinter using drag and drop. On mouse ButtonRelease-1 I want to get the widget over which the mouse was released (myTextLabel2), so that I can change the row and column of that widgets with the row and column of the clicked widget (myTextLabel1).</p>
  <p>I tried search for the method that gets the widget at position x,y, put all I can find is the reverse, getting the position of widget not the other way arround.</p>
  <p>Here is my code so far:</p>
  <pre><code>from tkinter import *
  from functools import partial
  
  def changeOrder(widget1,widget2):
      widget1.grid(row=1,column=0)
      widget2.grid(row=0,column=0)
  
  def drag_start(event):
      print(event.x)
  
  def drag_motion(event):
      x = event.x
      y = event.y
      
  
  def drag_release(event):
      x = event.x
      y = event.y
      #I want to get the widget at position x,y, should be myTextLabel2
  
      #Then swap the rows and columns for myTextLabel2 and myTextLabel1
      
  
  root = Tk()
  
  
  myTextLabel1 = Label(root,text=&quot;Label 1&quot;)
  myTextLabel1.grid(row=0,column=0,padx=5,pady=5,sticky=E+W+S+N)
  myTextLabel1.bind(&quot;&lt;Button-1&gt;&quot;,drag_start)
  myTextLabel1.bind(&quot;&lt;B1-Motion&gt;&quot;,drag_motion)
  myTextLabel1.bind(&quot;&lt;ButtonRelease-1&gt;&quot;,drag_release)
  
  
  myTextLabel2 = Label(root,text=&quot;Label 2&quot;)
  myTextLabel2.grid(row=1,column=0,padx=5,pady=5,sticky=E+W+S+N)
  
  
  myButton = Button(root,text=&quot;Change order&quot;,command=partial(changeOrder,myTextLabel1,myTextLabel2))
  myButton.grid(row=3,column=0,padx=5,pady=5,sticky=E+W+S+N)
  
  
  root.mainloop()
  </code></pre>