Drag'n Drop

Drag and Drop functionality is something we're accustomed to in most software.
By default, python and tkinter don't provide it.

We've incorporated a couple of ways to include drag and drop functionality in appJar.

Drag'n Drop Between Widgets

There is a beta version of drag and drop between labels.

from appJar import gui

def drag(widget):
    print("Dragged from:", widget)

def drop(widget):
    print("Dropped on:", widget)

app = gui("dnd Demo")


app.addLabel("dragLab", "Drag Me")
app.addLabel("dropLab", "Drop Here")

app.setLabelDragFunction("dragLab", [drag, drop])


Advertisement why?

Drag'n Drop Between Applications

There is also a beta version of drag and drop between applications - at the moment, this has been seen to work on Mac OSX 10.11, Raspberry Pi, and Windows 7 & 10 - let us know of success on other distributions!

from appJar import gui

def externalDrop(data):
    print("Data dropped:", data)

app = gui("External dnd Demo")


app.addLabel("dropLab", "Drop Here")
app.setLabelDropTarget("dropLab", externalDrop)


Only certain widgets can be registered to receive Drop events:

Then, if you drag a file or a URI onto one of these widgets, the filename/URI will be copied.
Or, if it's an image, the image will be replaced.

If no function has been set, the contents of the widget will be replaced with the filename/URI.
If you'd rather append the URI/filename - set replace to be False.
If a function has been set, it will be called, passing in the filename/URI as the only parameter.

There is currently no support for registering Drag events.


NB. This is all in beta - long term, the plan is to combine all of this into one set of functions, and provide a unified drag and drop model, that will work across all widgets both within the application and between applications.