22 Sep turtle.Screen().setup() function in Python
The turtle.Screen().setup() function sets the size and position of the main window. This is a method of the Screen object, not the Turtle.
Syntax: turtle.setup(width=_CFG[“width”], height=_CFG[“height”], startx=_CFG[“leftright”], starty=_CFG[“topbottom”])
Parameters: width, height – integers (size in pixels or a fraction of the screen); startx, starty – integers (window position).
Let us see an example to implement the turtle.Screen.setup() function in Python:
Demo51.py
# turtle.Screen().setup() function in Python
# Code by Studyopedia
import turtle
window = turtle.Screen()
window.setup(width=600, height=400) # Set window size
window.title("Custom Sized Window")
t = turtle.Turtle()
t.forward(100)
window.exitonclick()
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.
- Set window size: window.setup(width=600, height=400) sets the window’s outer size to 600×400 pixels.
- Set title: window.title(“Custom Sized Window”) changes the window title bar text.
- Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
- Move forward: t.forward(100) draws a 100-unit line (pen down by default).
- Close on click: window.exitonclick() waits for a mouse click, then closes the window.
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