Skip to main content

Drag and Drop expansion for PySimpleGUI

Project description

psgdnd

Drag and Drop for PySimpleGUI

Description

Finally drag and drop! The long wait for drag-and-drop in the Tkinter port of PySimpleGUI might soon be over. psgdnd is a prototype release for using tkinterdnd2 to provide drag and drop functionality. In theory, this will work with all existing versions of PySimpleGUI.

psgdnd integrates tkinterdnd2 with PySimpleGUI and provides interfaces that are easy to use in a PySimpleGUI application.

This is super-early stage code and design, very much a work in progress. More experimenation and education needed, but in the meantime, give it a try and see if it'll meet your needs.

Installation using Pip

To get the most recent release to PyPI:

python -m pip install --upgrade psgdnd

To get the most up to date code that's not yet released, pip install directly from this repo by running:

python -m pip install --upgrade https://github.com/PySimpleGUI/psgdnd/zipball/main

Usage

To add drag and drop support to your window:

  1. Import psgdnd2 into your code
  2. Register which elements you want to accept drop events and the type drops to accept
  3. Add processing of Drop Events to your event loop

Demo Programs

There are a couple Demo Programs located in the folder Demo Programs. One is a very simple example that's shown below. The other is a desktop icon that can be dropped onto.

Simple File Drop

This simple example will accept filenames dropped onto the Input element. When dropped, the input element is updated to the filename or list of filenames.

import psgdnd as dnd
import PySimpleGUI as sg

"""
    Demo - Drag and Drop using tkinterdnd2

    Experimental drag and drop demo using tkinterdnd2 (you'll need to pip install it)
        python -m pip install tkinterdnd2
    Routes drop event through the window.read.

    Usage:
        * Register elements for drop events
            register_element_dnd(element, window, drop_type)

        * In event loop - drop events signaled via DropEvent object and value in values dict
            DropEvent object has fields:
                key
                element
                drop_type
                window
            values[event] = filename(s) or text that was dropped as a string            

    Copyright 2026 PySimpleGUI. All rights reserved.
"""


def main():
    layout = [[sg.Text('Filename to process')],
              [sg.Input(key="-INPUT-", expand_x=True), sg.FileBrowse('Browse')],
              [sg.Button("OK"), sg.Button("Cancel")]]

    # layout = [[sg.Column(layout, p=0, k='-COL-', expand_y=True, expand_x=True)]]  # if want to make the entire window the target

    window = sg.Window("File Drop Example", layout, finalize=True, auto_save_location=True, resizable=True)

    # register all elements to receive drop events
    for key, element in window.key_dict.items():
        dnd.register_element_dnd(element, window, dnd.DROP_TYPE_FILES)

    while True:
        event, values = window.read()
        # print(event, values)
        if event in (sg.WIN_CLOSED, "Cancel"):
            break
        if dnd.is_drop_event(event):                        # if it's a drag and drop event
            if event.key == '-INPUT-':                      # see what element was dropped on
                window['-INPUT-'].update(values[event])     # update the Input Element with text from event

    window.close()


if __name__ == '__main__':
    main()

Drop Onto Icon

Demo_Drag_and_Drop_Onto_Icon.pyw is a Drag and Drop program I've wanted to create using PySimpleGUI for a long time. It wasn't possible until psgdnd was released this month. It has operations I frequently use such as image format conversions and translating to/from English and Spanish.

screen recording

License & Copyright

Copyright 2026 PySimpleGUI. All rights reserved.

Licensed under LGPL3.

Contributing

We are happy to receive issues describing bug reports and feature requests! If your bug report relates to a security vulnerability, please do not file a public issue, and please instead reach out to us at issues@PySimpleGUI.com.

We do not accept (and do not wish to receive) contributions of user-created or third-party code, including patches, pull requests, or code snippets incorporated into submitted issues. Please do not send us any such code! Bug reports and feature requests should not include any source code.

If you nonetheless submit any user-created or third-party code to us, (1) you assign to us all rights and title in or relating to the code; and (2) to the extent any such assignment is not fully effective, you hereby grant to us a royalty-free, perpetual, irrevocable, worldwide, unlimited, sublicensable, transferrable license under all intellectual property rights embodied therein or relating thereto, to exploit the code in any manner we choose, including to incorporate the code into PySimpleGUI and to redistribute it under any terms at our discretion.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psgdnd-6.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psgdnd-6.0.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file psgdnd-6.0.1.tar.gz.

File metadata

  • Download URL: psgdnd-6.0.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for psgdnd-6.0.1.tar.gz
Algorithm Hash digest
SHA256 bd59a7d1e0ede52d21eb77026e1aa1f2bcfa5b7fd99b657ae48e215fb61873d3
MD5 408dcc28d30226ea26da8ae767eaf871
BLAKE2b-256 ee1251a296934ac0d23a6fffb1199911605b84c253a8c97193ddf17e07c7887b

See more details on using hashes here.

File details

Details for the file psgdnd-6.0.1-py3-none-any.whl.

File metadata

  • Download URL: psgdnd-6.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for psgdnd-6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28305acc019b17a58fdcff9a5aecd365d89a26d993edb0cacb9594935ee9a825
MD5 ca4dc7e469bfa13729e52710763a2414
BLAKE2b-256 35d4810f419b85ba26628cf8d95d2660e664ce6866b666d2f068e68efc4f6eb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page