Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_drag_img_plus.py -- https://pastelink.net/yxpk2mya
- from tkinter import *
- from PIL import ImageTk, Image
- from b64, io <<< rename b to base
- py_gif_b64='''\
- R0lGODlhQABAAPcAAAAAAAAPMwAXNwAaOAAYQwAbQQAdQQAbTwAeSwAWUQMmQgAjSwEnSwYuTwoo
- SggtSAwrSAAlVAAgWQAmWAAqVgAuVwAuXQcuWAw1TQs5Xhk0SQAsYwAxZAA1YQA0bAA6bAA/dyw/
- UAxAbgxGeh5BYRxHbRRKdBRNfi5IXC5OaCJQdCNUfzdTajlQYj1UaTJWdDZge0BXaUZZaE1dakJa
- cEBffElhc0lieUlmfU9leQZJgBRVjB5bjypehzNXhzFbgTlchiZjljhkhzRplixtozNwozF1qzp4
- q0BehERmhENli0dshUZvjktylk1wkE92kltvgVBwiVp1g1lyiVl1il95j1B3l1V3klh6lmB2iWt7
- lUWDuUaIvEqCskmGul6Col2FqVSLtVONvVqMtl+NsWaInmmAlGyGnHOGlHGHmXGKnnqJk3mMm3uR
- lX2Qn2SGpmqIoW+Pp2yOrGeRuXGLoneOoHaPo3STp3eSrXyRonWZuX2gvmOWwW2aw2meynOfwnGh
- yXuhw3yly3iqz3ypz3Sl0HCp1pt+Ha6ED6SAE6yDGqeRF7OEBbqTCriTFr6fEKyJLaODMKWWJqWS
- M7WTI7aWN62iJrqlKrekOJiOR5uRTKSTRqaXVa2bV7mZR7mdVKmeZ62da62ec7Cfd7ujRrCmXrGt
- W7yoWq6jaqyicbWga7OpbbqpbbSrebmueMGXC8SaFcSZJcOcNcqjGtSoHc2pJ8yrOcG1P9iuKdG4
- LdC5PtmwPNq5MN29PcurScqtWtG8S9uwS9G8X921Xsmvbc2yd9C9cN/AUNHAfeHKRePMUuDDYOTP
- ZODFcubPdOLIfoKPmIGZq4qcrIGasYedsYOgs4eiv5euvoSjwIapx4KozYSrzI6wzoaw1Iux1Y+1
- 1oq12JSyz5K00Ji305i72qC706C92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T1Ri
- +auX+SmUzfNkN+PYwzgG7Xchi+57ghjR/70rCKfPc24pO87L8MUwfLH08It/ILkPqjEaTf9hFBX8
- 7n9/QXLP//73f0cBAQA7'''
- b64_img = b64---.b64decode(py_gif_b64)
- logo = Image.open(io.BytesIO(b64_img))
- logo = logo.convert("RGBA")
- root = Tk()
- canvas = Canvas(root,width=400,height=400)
- canvas.pack()
- logo = ImageTk.PhotoImage(logo)
- class Cv():
- x,y=0,0
- xx,yy=0,0
- objv=False
- cv=Cv()
- obj = {1: (50,50), 2: (80,90)}
- canvas.create_image(obj[1],image=logo)
- canvas.create_image(obj[2],image=logo)
- def click(event):
- x, y = (event.x, event.y)
- cv.objv = canvas.find_closest(x,y)[0]
- cv.xx, cv.yy = obj[cv.objv]
- if x < cv.xx+32 and x > cv.xx-32 and y < cv.yy+32 and y > cv.yy-32:
- cv.xx, cv.yy = cv.xx-x, cv.yy-y
- canvas.lift(cv.objv) # vs canvas.lower()
- else: cv.objv = False
- def drag(event):
- if cv.objv:
- x, y = (event.x, event.y)
- z = cv.xx+x, cv.yy+y
- canvas.coords(cv.objv, z)
- obj[cv.objv] = z
- canvas.bind('<Button-1>',click)
- canvas.bind('<B1-Motion>',drag)
- root.mainloop()
Add Comment
Please, Sign In to add comment