I am a making a blackjack game with cards using turtle and each time I play a hand turtle just prints over the last game instead of clearing the window. Is there a method that closes the window when it is called or is there another why of doing this?
-
Sorry if I'm misunderstanding, but do you want [`turtle.clear()`](https://docs.python.org/3.1/library/turtle.html#turtle.clear)? – cmrn Dec 02 '15 at 02:09
-
To my understanding turtle.clear() only gets rid of the last thing that turtle had drawn. I need to remove multiple things. – Allie Hart Dec 02 '15 at 02:22
2 Answers
I want to clarify what various turtle functions do as there are misunderstandings in this discussion, including in the currently accepted answer, as the method names themselves can be confusing:
turtle.mainloop()
aka turtle.Screen().mainloop()
Turns control over to tkinter's event loop. Usually, a lack of turtle.Screen().mainloop()
(or turtle.Screen().exitonclick()
, etc.) will cause the window to close just because the program will end, closing everything. This, or one of its variants, should be the last statement in a turtle graphics program unless the script is run from within Python IDLE -n.
turtle.done()
(Does not close window nor reset anything.) A synonym for turtle.mainloop()
turtle.clear()
Deletes everything this turtle has drawn (not just the last thing). Otherwise doesn't affect the state of the turtle.
turtle.reset()
Does a turtle.clear()
and then resets this turtle's state (i.e. direction, position, etc.)
turtle.clearscreen()
aka turtle.Screen().clear()
Deletes all drawing and all turtles, reseting the window to it's original state.
turtle.resetscreen()
aka turtle.Screen().reset()
Resets all turtles on the screen to their initial state.
turtle.bye()
aka turtle.Screen().bye()
Closes the turtle graphics window. I don't see a way to use any turtle graphics commands after this is invoked.
turtle.exitonclick()
aka turtle.Screen().exitonclick()
After binding the screen click event to do a turtle.Screen().bye()
invokes turtle.Screen().mainloop()
It's not clear that you can close and reopen the graphics window from within turtle without dropping down to the tkinter level that underpins turtle (and Zelle's graphics.py)
For purposes of starting a new hand in your blackjack game, I'd guess turtle.reset()
or turtle.resetscreen()
are your best bet.

- 40,441
- 5
- 32
- 81
turtle.clear()
turtle.reset()

- 11
- 1
-
From Review: Hi, while links are a great way of sharing knowledge, they won't really answer the question if they get broken in the future. Add to your answer the essential content of the link which answers the question. In case the content is too complex or too big to fit here, describe the general idea of the proposed solution. Remember to always keep a link reference to the original solution's website. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – sɐunıɔןɐqɐp Feb 12 '21 at 10:21