I am having problems with the following code although it is very simple. The error has to do with the python turtle library, and I've been fighting for a few days. When I run the code for the first time, it works. But when I close the window of the turtle popup and run the code again, an error appears and I have to restart the kernel so that it works again. I attach the code:
import turtle as t
def draw_chart():
alex = t.Turtle()
alex.fd(50)
window = t.Screen()
window.bgcolor('white')
window.setup(600,600)
draw_chart()
window.mainloop()
And I get the following error:
----------------------------------------------------------------------------
Terminator Traceback (most recent call last)
<ipython-input-4-c21753aaf0da> in <module>
5 window.title('Buscaminas')
6
----> 7 draw_chart(window)
8
9 window.mainloop()
<ipython-input-3-c74be4cddd4a> in draw_chart(finestra)
1 import turtle as t
2 def draw_chart(finestra):
----> 3 alex = t.Turtle()
4 alex.st()
5 alex.fd(50)
...\python\python37-32\lib\turtle.py in __init__(self, shape, undobuffersize, visible)
3814 shape=shape,
3815 undobuffersize=undobuffersize,
-> 3816 visible=visible)
3817
3818 Pen = Turtle
...\python\python37-32\lib\turtle.py in __init__(self, canvas, shape, undobuffersize, visible)
2555 self._undobuffersize = undobuffersize
2556 self.undobuffer = Tbuffer(undobuffersize)
-> 2557 self._update()
2558
2559 def reset(self):
...\python\python37-32\lib\turtle.py in _update(self)
2658 return
2659 elif screen._tracing == 1:
-> 2660 self._update_data()
2661 self._drawturtle()
2662 screen._update() # TurtleScreenBase
...\python\python37-32\lib\turtle.py in _update_data(self)
2644
2645 def _update_data(self):
-> 2646 self.screen._incrementudc()
2647 if self.screen._updatecounter != 0:
2648 return
...\python\python37-32\lib\turtle.py in _incrementudc(self)
1290 if not TurtleScreen._RUNNING:
1291 TurtleScreen._RUNNING = True
-> 1292 raise Terminator
1293 if self._tracing > 0:
1294 self._updatecounter += 1
Terminator:
Thank you very much in advance.