]> 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:01:53 +0000 (11:01 +0000)
committerRobert Schuppenies <okkotonushi@googlemail.com>
Sun, 10 Aug 2008 11:01:53 +0000 (11:01 +0000)
menu entries were not deleted.

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

index 7b116d9bb38d3f2e8bcbb3df89acfd228ff20b46..00ee2c8454644b4e58f3e78a4d3c9259261948e2 100644 (file)
@@ -2659,7 +2659,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 a2669c6c2bd111514ccfc65111d035db37ba8d2e..a197efc7a0e74128f9dfdb40b55e04e2090c32f6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1342811: Fix leak in Tkinter.Menu.delete. Commands associated to
+  menu entries were not deleted.
+
 - Copied the implementation of reduce() to _functools.reduce() to have a
   version that did not raise a DeprecationWarning under -3.