Nov-01-2019, 12:44 PM
I have a simple tkinter menu example that opens a new window on click.
When the Turtle window is opened it works fine the first time.
But when closed and opened again.
I get the following error and the turtle does not draw.
I need to figure out how to remove the turtle on exit some how.
Any ideas?
When the Turtle window is opened it works fine the first time.
But when closed and opened again.
I get the following error and the turtle does not draw.
I need to figure out how to remove the turtle on exit some how.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ python menu1.py circle Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.7/tkinter/__init__.py" , line 1705 , in __call__ return self .func( * args) File "menu1.py" , line 54 , in turtle1 t = turtle.Turtle() File "/usr/lib/python3.7/turtle.py" , line 3816 , in __init__ visible = visible) File "/usr/lib/python3.7/turtle.py" , line 2557 , in __init__ self ._update() File "/usr/lib/python3.7/turtle.py" , line 2660 , in _update self ._update_data() File "/usr/lib/python3.7/turtle.py" , line 2646 , in _update_data self .screen._incrementudc() File "/usr/lib/python3.7/turtle.py" , line 1292 , in _incrementudc raise Terminator turtle.Terminator |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from tkinter import * import turtle root = Tk() def circle(t,x,y): print ( "circle" ) t.down() t.color( "#ff0000" ) for i in range ( 0 , 20 ): t.forward( 10 ) t.rt( 18 ) def turtle1(): x = 0 ; y = 0 w = turtle.Screen() w.setup( 1000 , 700 ) w.clear() w.bgcolor( "#ffffff" ) t = turtle.Turtle() circle(t,x,y) w.exitonclick() def newWin1(): # new window definition newwin = Toplevel(root) display = Label(newwin, text = "Window 1" ) display.pack() def newWin2(): # new window definition newwin = Toplevel(root) display = Label(newwin, text = "Window 2" ) display.pack() button1 = Button(root, text = "Window 1" , command = newWin1) button2 = Button(root, text = "Window 2" , command = newWin2) button3 = Button(root, text = "Turtle Window" , command = turtle1) button1.pack() button2.pack() button3.pack() root.mainloop() |