i want to create an app where in tkinter widgets can be draged. for the purpose I written following code but the problem is while dragging, the mouse pointer value (event.x, event.y) is different from widget.place() x and y value so the mouse pointer is way down but the widget is not moving far enough.
from tkinter import *
import tkinter as tk
window = tk.Tk()
window.geometry('500x500+100+100')
window.title('testing')
global pressed
pressed = FALSE
def drag(event):
global pressed
pressed = TRUE
def drop(event):
global pressed
pressed = FALSE
def move(event):
global pressed
if pressed == TRUE:
x_pointer, y_pointer = event.x, event.y
label1.place(x=x_pointer, y=y_pointer)
print('{}, {}'.format(x_pointer, y_pointer))
label1 = Label(window, text='Drag Me', width=10)
label1.place(x=10, y=10)
label1.bind('<ButtonPress>', drag)
label1.bind('<ButtonRelease>', drop)
label1.bind('<Motion>', move)
window.mainloop()