diff options
author | Guido van Rossum <guido@python.org> | 1998-10-24 14:03:48 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-10-24 14:03:48 (GMT) |
commit | a96c2d407bbbc27c516c211e12802b9a6698f727 (patch) | |
tree | 72371aec7d0c3c909296c7be347541f2ce9a4843 /Tools | |
parent | c62cf36e7630c73a5bc2309430b836cd616bb718 (diff) | |
download | cpython-a96c2d407bbbc27c516c211e12802b9a6698f727.zip cpython-a96c2d407bbbc27c516c211e12802b9a6698f727.tar.gz cpython-a96c2d407bbbc27c516c211e12802b9a6698f727.tar.bz2 |
Cope with destruction of the window
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/idle/turtle.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/Tools/idle/turtle.py b/Tools/idle/turtle.py index 8d2be56..15b4138 100644 --- a/Tools/idle/turtle.py +++ b/Tools/idle/turtle.py @@ -210,12 +210,16 @@ class RawPen: arrow="last", capstyle="round", fill=self._color) - for i in range(1, 1+nhops): - x, y = x0 + dx*i/nhops, y0 + dy*i/nhops - self._canvas.coords(item, x0, y0, x, y) - self._canvas.update() - self._canvas.after(10) - self._canvas.itemconfigure(item, arrow="none") + try: + for i in range(1, 1+nhops): + x, y = x0 + dx*i/nhops, y0 + dy*i/nhops + self._canvas.coords(item, x0, y0, x, y) + self._canvas.update() + self._canvas.after(10) + self._canvas.itemconfigure(item, arrow="none") + except Tk.TclError: + # Probably the window was closed! + return else: item = self._canvas.create_line(x0, y0, x1, y1, width=self._width, @@ -226,6 +230,7 @@ class RawPen: _root = None _canvas = None +_pen = None class Pen(RawPen): @@ -233,13 +238,25 @@ class Pen(RawPen): global _root, _canvas if _root is None: _root = Tk.Tk() + _root.wm_protocol("WM_DELETE_WINDOW", self.destroy) if _canvas is None: # XXX Should have scroll bars _canvas = Tk.Canvas(_root, background="white") _canvas.pack(expand=1, fill="both") RawPen.__init__(self, _canvas) -_pen = None + def destroy(self): + global _root, _canvas, _pen + self.clear() + if self is _pen: + _pen = None + root = _root; _root = None + canvas = _canvas; _canvas = None + if root: + try: + root.destroy() + except Tk.TclError: + pass def _getpen(): global _pen |