22 Sep turtle.bye() function in Python
The turtle.bye() function shuts the turtle graphics window and ends the drawing session. This is the programming way to close the window.
Syntax: turtle.bye()
Parameters: None.
Let us see an example to implement the turtle.bye() function in Python:
Demo60.py
# turtle.bye() function in Python # Code by Studyopedia import turtle window = turtle.Screen() t = turtle.Turtle() t.forward(100) # Close turtle graphics window after 3 seconds window.ontimer(window.bye, 3000) window.mainloop()
The following is the output:

In the above code, we followed the below steps:
- Import module: import turtle loads the turtle graphics library.
- Create screen: window = turtle.Screen() opens the drawing window.
- Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
- Move forward:forward(100) draws a 100-unit line (pen down by default).
- Schedule close:ontimer(window.bye, 3000) schedules window.bye() to run after 3000 milliseconds (3 seconds), which closes the window.
- Run event loop:mainloop() starts the event loop so timers and events work; the window stays responsive until it’s closed.
If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- OpenCV Tutorial
- Python Tutorial
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- Generative AI Tutorial
- LangChain Tutorial
- RAG Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments