TkinterDnd.Tk() event.data format

Question:

When using TkinterDnd.Tk() to drop external files into the tk window, the event argument from the handler function has the paths of the files on a single string, separated by whitespaces.

def handle_drop(event):
    paths = event.data.strip()


drop_zone.dnd_bind('<<Drop>>', handle_drop)

So by adding .split() to paths, I get them individually.

But my problems appear when the path itself has a whitespace on it. I can no longer split the paths.

I opened an issue on the github repo but no answer yet.

So, before you tell me to not have whitespaces on the paths, well, thats not my problem. I can’t tell people how to manage their files.

So I was wondering if you guys could help me to solve this problem.

EDIT:

Example:

-- /path1/subfolder with spaces/file.txt
-- /path1/subfolder with spaces/video goat.avi

Lets say I drag these 2 files into the tkinter window.

event.data will contain the following

"/path1/subfolder with spaces/file.txt /path1/subfolder with spaces/video goat.avi"

A single string, so if I call event.data.strip().split() I will get something like:

["/path1/subfolder", "with", "spaces/file.txt", "/path1/subfolder", "with", "spaces/video", "goat.avi"]

Asked By: Azazel

||

Answers:

Never mind, paths are inside {} now, so gg

Answered By: Azazel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.