Giter Club home page Giter Club logo

tkinterdnd's People

Contributors

rdbende avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tkinterdnd's Issues

DnD and modal windows

When a modal window displays (e.g. messagebox) whilst the parent window widgets are disabled, it is still possible to dnd into the parent window.

Attached is your example from the PyPi website. I have added two buttons:

  • The "Press Test" button prints 'Hi' to show it is active.
  • The "Call messagebox" button invokes a messagebox.

Invoke the messagebox, now drag filenames to your dnd enabled area. DnD does not comply with the behaviour of other tk widgets, which are disabled by the invocation of the modal (messagebox) window.

Kind regards
Issue with DnD and modal windows.txt

_tkinter.TclError: expected integer but got "%#"

root = Tk()
root.register_drop_target("*")
root.bind("<<Drop>>", print)
root.mainloop()

After dragging a file onto the window, I got this:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1947, in __call__
    args = self.subst(*args)
           ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1632, in _substitute
    e.serial = getint(nsign)
               ^^^^^^^^^^^^^
_tkinter.TclError: expected integer but got "%#"

issue with a file DnD on Windows, from external app to Python app with this library

(Originally posted in python/cpython, closed there and opened here because of using this repo's library.)

Handling of a Drag-n-Drop event with tkinter causes an exception:

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1920, in __call__
    args = self.subst(*args)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1605, in _substitute
    e.serial = getint(nsign)  
_tkinter.TclError: expected integer but got "%#"

The basic code used is this (more code is in the app, but this should be the relevant parts of the setup):

def drop(event):
        print("DROP EVENT:", event) # test code to see what's delivered

import tkinterDnD
root = tkinterDnD.Tk()
root.register_drop_target("*")
root.bind("<<Drop>>", drop)

The intent is to capture a file dragged from another application. With the 'register' function, this Python program and the OS indicate that the program's window is a valid place to drop a file dragged from a file manager program (specifically using Windows Explorer). After 'dropping', the error shown above is seen.

Environment:
CPython versions tested on: Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0
Operating system and architecture: Windows 10

Example not working anymore

Hi there,

The example given on the main page doesn't work anymore. Python 3.11

Any reasons why? Installed right the module..

Try version 2.8 from SOURCEFORGE if you run into errors with version 2.9.2

Try version 2.8 from SOURCEFORGE if you run into errors with version 2.9.2.

I installed using pip, had issues, so I downgraded to 2.8 by replacing the file contents of version 2.9.2 with those from 2.8, but I kept utils from 2.9.2 in the install location - no errors after that and drag and drop worked fine.

I will expand upon this further at a later time with more descriptive info and file locations.

Just brief for now.

Edit:

pip install python-tkdnd | known as: python-tkdnd 0.2.1 (~ https://pypi.org/project/python-tkdnd/ ~) | but this installed: tkinterDnD 2.9.2 | but this version was causing trouble; errors and such, so I manually replaced it with version 2.8 that was manually downloaded from SOURCEFORGE: (tkdnd2.8-win32-ix86.tar.gz) ~ https://sourceforge.net/projects/tkdnd/files/ ~, but tkdnd_utils.tcl from 2.9.2 was kept by me to stay with the 2.8 replacement version though and left in its directory. %USERPROFILE%\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tkinterDnD\windows | This is the location where the files were replaced. My application's drag and drop is now working. import tkinter as tk; from tkinter import ttk, filedialog; import tkinterDnD. Just wanted to share this in case anyone else found themselves experiencing problems.

If I can find my history of any of the actual errors that occurred at the time with version 2.9.2, I'll edit this again and include those here as well.

Edit2:

Error section:

TkDnDVersion = master.tk.call('package', 'require', 'tkdnd')
_tkinter.TclError: couldn't load library "%USERPROFILE%\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tkinterDnD\windows/libtkdnd2.9.2.dll"

So, it seemed that there was an issue with loading the libtkdnd2.9.2.dll dynamic link library file which is required by TkinterDnD. This error indicated to me that that the DLL file could not be loaded, which that likely caused the TkDnDVersion initialisation to fail.

AND I THINK I HAVE JUST CRACKED WHY - POTENTIALLY VERSION 2.9.2 MAY HAVE TYPO'D THE FOLLOWING FOLDER:

Correct:
Python\Python36-32\Lib\site-packages\tkinterDnD

Incorrect:
Python\Python36-32\lib\site-packages\tkinterDnD

It's very subtle but in the directory: Python36-32
There are two folders:
One named: libs
And one named: Lib
And the latter folder has a CAPITAL, L - and maybe the DLL failed to load for me due to version 2.9.2 having made a typo and used a lower case, l.
This could explain the error and why it could not load the DLL for me, but I cannot confirm this though. I am speculating.


pip show python-tkdnd
Name: python-tkdnd
Version: 0.2.1 | tkinterDnD 2.9.2 which was installed like this: pip install python-tkdnd, but this version was manually replaced by user with version 2.8 that was manually downloaded from SOURCEFORGE: (tkdnd2.8-win32-ix86.tar.gz) | ~ https://sourceforge.net/projects/tkdnd/files/ ~ |, but tkdnd_utils.tcl from 2.9.2 was kept with the 2.8 version though.
Summary: Native drag & drop capabilities in tkinter. The tkinterDnD package is a
nice and easy-to-use wrapper around the tkdnd tcl package.
Home-page: https://github.com/rdbende/tkinterDnD
Author: rdbende
Author-email: [email protected]
License: MIT license
Location: c:\users\X\appdata\local\programs\python\python36-32\lib\site-packages
Requires: ttkwidgets

Resources I've been to; random list:

https://pypi.org/project/python-tkdnd/

https://sourceforge.net/projects/tkdnd/files/

https://sourceforge.net/projects/tkdnd/

https://github.com/petasis/tkdnd

https://github.com/petasis/tkdnd/issues

petasis/tkdnd#64

petasis/tkdnd#53

https://mail.python.org/pipermail/tkinter-discuss/2005-July/000476.html

https://stackoverflow.com/questions/75526264/using-drag-and-drop-files-or-file-picker-with-customtkinter

https://docs.python.org/3/library/tkinter.dnd.html

https://github.com/rdbende/tkinterDnD

https://github.com/rdbende/tkinterDnD/issues

#9

Check what works

Action GNOME Plasma Windows macOS
Text dropping
Text dragging
File dropping
File dragging
Color dropping
Color dragging
HTML dropping

Hook for DnD events

Creating a hook with ttkwidgets.hook so that you don't have to write an entire widget like this, but you can easily handle the dnd events specified with arguments

class DnDFrame(tk.Frame):
    def __init__(self, *args, **kwargs):
        onfiledrop = kwargs.pop("onfiledrop", None)
        ontextdrop = kwargs.pop("ontextdrop", None)
        ondrop = kwargs.pop("ondrop", None)
        ondragstart = kwargs.pop("ondragstart", None)
        ondragend = kwargs.pop("ondragend", None)
        ondragenter = kwargs.pop("onadragenter", None)
        ondragleave = kwargs.pop("ondragleave", None)
        ondragmove = kwargs.pop("ondragmove", None)
        
        tk.Frame.__init__(self, *args, **kwargs)
        
        if onfiledrop:
            self.bind("<<Drop:DND_Files>>", onfiledrop)
            self.register_drop_target("DND_Files")
        if ontextdrop:
            self.bind("<<Drop:DND_Text>>", ontextdrop)
            self.register_drop_target("DND_Text")
        if ondrop:
            self.bind("<<Drop>>", ondrop)
            self.register_drop_target("*")
        if ondragstart:
            self.bind("<<DragInitCmd>>", ondragstart)
            self.register_drag_source()
        if ondragend:
            self.bind("<<DragEndCmd>>", ondragend)
            self.register_drag_source()
        if ondragenter:
            self.bind("<<DropEnter>>", ondragenter)
            self.register_drop_target("*")
        if ondragleave:
            self.bind("<<DropLeave>>", ondragleave)
            self.register_drop_target("*")
        if ondragmove:
            self.bind("<<DropPosition>>", ondragmove)
            self.register_drop_target("*")
            
    def bind(self, sequence=None, func=None, add=None):
        """
        I want to handle simple events like <<Drop:File>> instead of
        <<Drop:DND_Files>>, but I can't do it with `event_add`,
        so I'm rewriting the bind
        """
        
        if sequence == "<<Drop:File>>":
            sequence = "<<Drop:DND_Files>>"
        elif sequence == "<<Drop:Text>>":
            sequence = "<<Drop:DND_Files>>"
        elif sequence == "<<Drop:Any>>":
            sequence = "<<Drop>>"
            
        return tk.Frame.bind(self, sequence, func, add)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.