You can create a visual program where you can drag and drop pictures around on the screen using GUI library Tkinter in Python.
Here is an example code that allows you to drag and drop a picture on a canvas using Tkinter:
main.py1322 chars43 lines
In the above code, we create a class DragAndDrop
which is inherited from Tkinter's Frame class.
We create a canvas widget and add an image to it using the create_image
method. We bind three events to the image tag: <ButtonPress-1>
for mouse left button press, <ButtonRelease-1>
for mouse left button release, and <B1-Motion>
for mouse motion.
When the <ButtonPress-1>
event is triggered, we create a rectangle around the image. When the <ButtonRelease-1>
event is triggered, we delete the rectangle. When the <B1-Motion>
event is triggered, we move the rectangle with the mouse cursor.
Run this python code, it will create a window with an image. You can drag and drop the image around by clicking the left mouse button on the image, hold the click button and move the mouse.
gistlibby LogSnag