You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
1 year ago
|
import tkinter as tk
|
||
|
from time import sleep
|
||
|
|
||
|
def start_drag(event):
|
||
|
global current_coords
|
||
|
global dragged_item
|
||
|
dragged_item = label
|
||
|
current_coords = label.winfo_pointerx(), label.winfo_pointery()
|
||
|
|
||
|
def stop_drag(event):
|
||
|
dragged_item = None
|
||
|
|
||
|
def drag(event):
|
||
|
global current_coords
|
||
|
xc, yc = label.winfo_pointerx(), label.winfo_pointery()
|
||
|
dx, dy = xc - current_coords[0], yc - current_coords[1]
|
||
|
current_coords = xc, yc
|
||
|
label.place(x=label.winfo_x() + dx, y=label.winfo_y() + dy)
|
||
|
|
||
|
def nn(root,im):
|
||
|
global label
|
||
|
|
||
|
image = tk.PhotoImage(file=im) # Use self.image
|
||
|
label = tk.Label(root, image=image)
|
||
|
label.image = image # Keep a reference to the image
|
||
|
label.pack()
|
||
|
|
||
|
dragged_item = None
|
||
|
current_coords = 0, 0
|
||
|
|
||
|
label.bind('<ButtonPress-1>', start_drag)
|
||
|
label.bind('<ButtonRelease-1>', stop_drag)
|
||
|
label.bind('<B1-Motion>', drag)
|
||
|
# globals().update(locals())
|
||
|
|
||
|
while True:
|
||
|
tk.Misc.lift(label)
|
||
|
sleep(0.05)
|
||
|
|
||
|
print("Image cords: ", label.winfo_x(), 670 - label.winfo_y())
|
||
|
#x1, y1 = image.coords(image)
|
||
|
# print(f'Image cords: {}')
|