Chapter: Coding with Python Turtle

Python Turtle Programming Notes Class 7-12 | CBSE Bihar Board | Pratap Sanjay Sir

🐢 Python Turtle
Complete Notes

CBSE • Python • Class 7

📚 CBSE Class 7 📖 CBSE Board 💻Pratap Sanjay Sir
By Pratap Sanjay Sir
pratapsanjaysir.blogspot.com
🚀 Start Learning
1
Starting Python

Python is a high-level programming language. It is easy to learn and understand.Python is used for drawing, games, animations, and problem-solving. The Turtle module helps us draw pictures using code.

2
Create New File
  1. 📂 Open IDLE/VS Code/Python Editor.
  2. 📄 Click on File → New File
  3. 💾 Save the file with .py extension
    Example: turtle1.py
  4. ▶️ Write your Python code and run it.
3
Turtle Programming

🐢 Turtle Turtle is like a pen that moves on the screen. We give commands and the turtle draws shapes. The screen is called the canvas.

4
Import Turtle
import turtle as t

This line imports the turtle module.

t is a short name (alias) for turtle.

5
Moving Turtle
Cart Image
Forward ➡️
t.forward(100)
Backward ⬅️
t.backward(100)
Left Turn ↺
t.left(90)
Right Turn ↻
t.right(90)

→ Distance is given in pixels. Angle is given in degrees.

6
Draw Square
import turtle as t for i in range(4): # Loop 4 times t.forward(100) t.right(90) t.done()

Square = 4 equal sides, 90° angles! 🔲

7
Filling in an Image (Adding Color)
Background Color
t.bgcolor("color")

Example: red, blue, green, black ...etc.

Fill Color
t.fillcolor("color")
Pen Color
t.pencolor("color")
Pen Size
t.pensize(n)

n → can be any numeric number.

Fill a Shape

t.fillcolor("red")
t.begin_fill()

# drawing code here

t.end_fill()
        


Example:


t.fillcolor("blue")
t.begin_fill()

for i in range(4):
    t.forward(100)
    t.right(90)

t.end_fill()
        

Explanation:
fillcolor() ⟶ sets the color to be filled inside the shape.
begin_fill() ⟶ starts the filling process.
end_fill() ⟶ completes the filling of the shape.

8
Changing the Speed of Drawing
Speed of the Turtle
t.speed(value)

Explanation:
value → speed of the turtle (0 to 10).
0 → No animation.
1 → Slowest.
3 → Slow.
6 → Normal.
10 → Fast.
10+ → fastest speed.

9
Drawing a Circle
Circle Command
t.circle(50)

Explanation:
50 → radius of the circle.
Turtle automatically draws a circle.

10
Drawing a Customized Circle
Customized Circle
t.circle(100, 180)

Explanation:
100 → radius of the circle.
180 → angle of the circle.
Draws a half circle. Useful for arcs and designs.

11
Change the Pen Direction
Set Heading

t.setheading(0)    # East
t.setheading(90)   # North
t.setheading(180)  # West
t.setheading(270)  # South
            

Explanation:
Sets turtle direction directly.
Angle is measured in degrees.

12
Clearing the Screen
Clear Command
t.clear()

Explanation:
Clears only the drawing.
Turtle remains at the same position.

13
Resetting the Environment
Reset Command
t.reset()

Explanation:
Clears the screen.
Moves turtle to starting position.
Restores default settings.

14
Leaving a Stamp
Stamp Command
t.stamp()

Explanation:
Leaves a turtle shape on the screen.
Turtle can move, but the stamp remains.

Example:


t.forward(50)
t.stamp()
t.forward(50)
t.stamp()
            
15
Cloning of a Turtle
Clone Command
t1 = t.clone()

Explanation:
Creates a copy of the turtle.
Both turtles can draw independently.

Example:


t1 = t.clone()
t1.left(90)
t1.forward(100)
            
16
Ending the Program
Done Command
t.done()

Explanation:
Keeps the turtle window open.
Used at the end of the program.




Best Python Turtle Coding Resources

Click on the cards below to explore quality Python Turtle examples and projects.






Python Turtle Project Ideas - # pratapsanjaysir

Image Viewer


Chapter 12 – Coding With Python Turtle Que. & Ans.
Click here to access all Questions & Answers
Visit Now ⤴
😊
🔔 Subscribe to My Channel

Post a Comment

0 Comments