Skip to content

Suggested change to dnd.py to better work with multiple top level windows. #143425

@f34rdotcom

Description

@f34rdotcom

I had issues with multiple windows. My initial widget and my destination widget were different top level windows.
This solution worked well and I can't think of any reason it would break the existing code. Would be good to check if a valid widget first.

tested. ish...

--- dnd.py      2026-01-04 20:08:11.713697389 -0800
+++ ../dnd.py   2026-01-04 20:10:04.273009496 -0800
@@ -151,7 +151,7 @@
 
     def on_motion(self, event):
         x, y = event.x_root, event.y_root
-        target_widget = self.initial_widget.winfo_containing(x, y)
+        target_widget = event.widget.winfo_toplevel().winfo_containing(x, y)
         source = self.source
         new_target = None
         while target_widget is not None:

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions