python-tkdnd


Namepython-tkdnd JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/rdbende/tkinterDnD
SummaryNative drag & drop capabilities in tkinter. The tkinterDnD package is a nice and easy-to-use wrapper around the tkdnd tcl package.
upload_time2021-07-31 13:45:45
maintainer
docs_urlNone
authorrdbende
requires_python>=3.6
licenseMIT license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tkinterDnD
A nice and easy-to-use wrapper around the tkdnd package. No tcl installation, no build is required, **just install and use it!**

## Install
The Pypi name is python-tkdnd, because tkinterDnD was already taken, but you can import the package as `tkinterDnD`

```
pip3 install python-tkdnd
```
or if you're using a distro like Windows 7, 10, or 11 replace `pip3` with `pip`


## Credits
```
Copyright (c) 2021 rdbende
Copyright (c) 2012-2020 Petasis - the tkdnd package
Copyright (c) 2020 Philippe Gagné - for Mac binaries
Copyright (c) 2017 Michael Lange - the TkinterDnD package
```

## Little example
```python
import tkinter as tk
from tkinter import ttk
import tkinterDnD  # Importing the tkinterDnD module

# You have to use the tkinterDnD.Tk object for super easy initialization,
# and to be able to use the main window as a dnd widget
root = tkinterDnD.Tk()  
root.title("tkinterDnD example")

stringvar = tk.StringVar()
stringvar.set('Drop here or drag from here!')


def drop(event):
    # This function is called, when stuff is dropped into a widget
    stringvar.set(event.data)

def drag_command(event):
    # This function is called at the start of the drag,
    # it returns the drag type, the content type, and the actual content
    return (tkinterDnD.COPY, "DND_Text", "Some nice dropped text!")


# Without DnD hook you need to register the widget for every purpose,
# and bind it to the function you want to call
label_1 = tk.Label(root, textvar=stringvar, relief="solid")
label_1.pack(fill="both", expand=True, padx=10, pady=10)

label_1.register_drop_target("*")
label_1.bind("<<Drop>>", drop)

label_1.register_drag_source("*")
label_1.bind("<<DragInitCmd>>", drag_command)


# With DnD hook you just pass the command to the proper argument,
# and tkinterDnD will take care of the rest
# NOTE: You need a ttk widget to use these arguments
label_2 = ttk.Label(root, ondrop=drop, ondragstart=drag_command,
                    textvar=stringvar, padding=50, relief="solid")
label_2.pack(fill="both", expand=True, padx=10, pady=10)


root.mainloop()
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rdbende/tkinterDnD",
    "name": "python-tkdnd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "rdbende",
    "author_email": "rdbende@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3a/bf/06781b8ecdff505d021996fab9ebb8cc18606576f0ed34d0d6d75b337b6f/python-tkdnd-0.2.1.tar.gz",
    "platform": "",
    "description": "# tkinterDnD\nA nice and easy-to-use wrapper around the tkdnd package. No tcl installation, no build is required, **just install and use it!**\n\n## Install\nThe Pypi name is python-tkdnd, because tkinterDnD was already taken, but you can import the package as `tkinterDnD`\n\n```\npip3 install python-tkdnd\n```\nor if you're using a distro like Windows 7, 10, or 11 replace `pip3` with `pip`\n\n\n## Credits\n```\nCopyright (c) 2021 rdbende\nCopyright (c) 2012-2020 Petasis - the tkdnd package\nCopyright (c) 2020 Philippe Gagn\u00e9 - for Mac binaries\nCopyright (c) 2017 Michael Lange - the TkinterDnD package\n```\n\n## Little example\n```python\nimport tkinter as tk\nfrom tkinter import ttk\nimport tkinterDnD  # Importing the tkinterDnD module\n\n# You have to use the tkinterDnD.Tk object for super easy initialization,\n# and to be able to use the main window as a dnd widget\nroot = tkinterDnD.Tk()  \nroot.title(\"tkinterDnD example\")\n\nstringvar = tk.StringVar()\nstringvar.set('Drop here or drag from here!')\n\n\ndef drop(event):\n    # This function is called, when stuff is dropped into a widget\n    stringvar.set(event.data)\n\ndef drag_command(event):\n    # This function is called at the start of the drag,\n    # it returns the drag type, the content type, and the actual content\n    return (tkinterDnD.COPY, \"DND_Text\", \"Some nice dropped text!\")\n\n\n# Without DnD hook you need to register the widget for every purpose,\n# and bind it to the function you want to call\nlabel_1 = tk.Label(root, textvar=stringvar, relief=\"solid\")\nlabel_1.pack(fill=\"both\", expand=True, padx=10, pady=10)\n\nlabel_1.register_drop_target(\"*\")\nlabel_1.bind(\"<<Drop>>\", drop)\n\nlabel_1.register_drag_source(\"*\")\nlabel_1.bind(\"<<DragInitCmd>>\", drag_command)\n\n\n# With DnD hook you just pass the command to the proper argument,\n# and tkinterDnD will take care of the rest\n# NOTE: You need a ttk widget to use these arguments\nlabel_2 = ttk.Label(root, ondrop=drop, ondragstart=drag_command,\n                    textvar=stringvar, padding=50, relief=\"solid\")\nlabel_2.pack(fill=\"both\", expand=True, padx=10, pady=10)\n\n\nroot.mainloop()\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Native drag & drop capabilities in tkinter. The tkinterDnD package is a nice and easy-to-use wrapper around the tkdnd tcl package.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/rdbende/tkinterDnD"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "952850130cd6667454c7c04100e8697e70c03428c8a672ba0f60601b6a6f1e02",
                "md5": "2a2e56ff566e0a4e07c0f7924efcce70",
                "sha256": "e476f02c5a9f36361f494cb9e6bc4515790e224a22b4d14b8fbd90d7c1fc0e81"
            },
            "downloads": -1,
            "filename": "python_tkdnd-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a2e56ff566e0a4e07c0f7924efcce70",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 172610,
            "upload_time": "2021-07-31T13:45:44",
            "upload_time_iso_8601": "2021-07-31T13:45:44.000878Z",
            "url": "https://files.pythonhosted.org/packages/95/28/50130cd6667454c7c04100e8697e70c03428c8a672ba0f60601b6a6f1e02/python_tkdnd-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3abf06781b8ecdff505d021996fab9ebb8cc18606576f0ed34d0d6d75b337b6f",
                "md5": "081d6b466c6b3f09c9a67ad12af7f48d",
                "sha256": "dbce480c1ab5923075aa6fa02e8ae85b984886dfaf20c82d20d78420ad19451b"
            },
            "downloads": -1,
            "filename": "python-tkdnd-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "081d6b466c6b3f09c9a67ad12af7f48d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 157888,
            "upload_time": "2021-07-31T13:45:45",
            "upload_time_iso_8601": "2021-07-31T13:45:45.834403Z",
            "url": "https://files.pythonhosted.org/packages/3a/bf/06781b8ecdff505d021996fab9ebb8cc18606576f0ed34d0d6d75b337b6f/python-tkdnd-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-07-31 13:45:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rdbende",
    "github_project": "tkinterDnD",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "python-tkdnd"
}
        
Elapsed time: 1.29967s