]> granicus.if.org Git - python/commitdiff
Issue #1342811: Fix leak in Tkinter.Menu.delete. Commands associated to
authorRobert Schuppenies <okkotonushi@googlemail.com>
Sun, 10 Aug 2008 11:19:25 +0000 (11:19 +0000)
committerRobert Schuppenies <okkotonushi@googlemail.com>
Sun, 10 Aug 2008 11:19:25 +0000 (11:19 +0000)
menu entries were not deleted.

Backport from trunk r65622.

Lib/lib-tk/Tkinter.py
Misc/NEWS

index 6f00397650d019f2441eb3067aabb74bd45b45de..8874f02daa5f9101faa8de17aee0437de4433d42 100644 (file)
@@ -2669,7 +2669,17 @@ class Menu(Widget):
         self.insert(index, 'separator', cnf or kw)
     def delete(self, index1, index2=None):
         """Delete menu items between INDEX1 and INDEX2 (not included)."""
+        if index2 is None:
+            index2 = index1
+        cmds = []
+        for i in range(self.index(index1), self.index(index2)+1):
+            if 'command' in self.entryconfig(i):
+                c = str(self.entrycget(i, 'command'))
+                if c in self._tclCommands:
+                    cmds.append(c)
         self.tk.call(self._w, 'delete', index1, index2)
+        for c in cmds:
+            self.deletecommand(c)
     def entrycget(self, index, option):
         """Return the resource value of an menu item for OPTION at INDEX."""
         return self.tk.call(self._w, 'entrycget', index, '-' + option)
index 47cb3ef110a0ed7a1e62d3b18dad6365ae07a9d3..273e294097f8fc5e3f37d7e4a53cef655afd3550 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -74,6 +74,9 @@ Core and builtins
 Library
 -------
 
+- Issue #1342811: Fix leak in Tkinter.Menu.delete. Commands associated to
+  menu entries were not deleted.
+
 - Issue #799428: Fix Tkinter.Misc._nametowidget to unwrap Tcl command objects.
 
 - Issue #3339: dummy_thread.acquire() could return None which is not a valid