Class 9 - Python Turtle Module
Class 9 - Python Turtle Module
དཔལ་ལྡན་འབྲུག་གཞུང་།
ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
Python Coding
Class IX ICT Curriculum
January 2024
Key Concept # 4
TURTLE MODULE
Concept Overview
Coding Concept Sub-Concepts
● Importing the turtle module
● Turtle window setting - size(), title(), shape(),
bgcolor(), showturtle(), hideturtle()
● Turtle basic motions methods- forward(), backward(),
Python Turtle left(), right(), circle()
Module ● Turtle pen control methods - pencolor(), pensize(),
pendown(), penup(), speed(), goto(), setpos(),
setposition()
● Colour control - begin_fill(), end_fill()
● Text method - write()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
Objectives
The onscreen pen that you use for drawing is called the turtle.
The turtle can draw lines, and shapes and also change colours, sizes and
shapes.
The turtle can also be used to create complex shapes and images using
loops and functions.
See Results You can see what your code does instantly.
1 2
Direct import Import Everything
Using the import turtle Using the from turtle import *
statement - this imports the entire statement - this imports all of the
turtle module and allows you to functions and classes from the turtle
use all of its functions and module into the current namespace, so
classes. you don't have to use the turtle prefix
when calling them.
1 2
import turtle from turtle import *
Tk=turtle.Turtle() for x in range(4)
for x in range(4) forward(200)
Tk.forward(200) right(90)
Tk.right(90) done()
Tk.done()
Turtle Methods
● In Turtle graphics, a virtual turtle moves around the screen, and programmers
can control its movements and drawings using specific methods.
● The turtle can also be configured to change its colour, shape, and size using
various methods.
Turtle Methods
Window setting Basic motions Pen control Colour control Text method
ACTIVITIES
1
1. Understanding the Different
Window Settings Methods
WINDOW SETTING 2. Demo - Window Setting
3. Activity 1 - Window Setting
Demo - Solution
Code
Activity 1 - Solution
Code
1 #import the turtle module
2 from turtle import *
3 # Create a Turtle object with the shape "square"
4 shape("square")
5 #Change the window size height=400 and width=350
6 setup(height=400,width=350)
7 # Set the title of the Turtle window
8 title("This is a title to the window!")
9 # Set the background color of the window to pink
10 bgcolor("pink")
ACTIVITIES
1. Understanding Turtle Motions
and Motion Methods
2
2. Demo 1 - Drawing a Line
BASIC MOTIONS 3. Activity 1 - Drawing a Circle
4. Demo 2 - Drawing an Arc
5. Activity 2- Drawing a Square
6. Activity 3 - Drawing an Ice Cream
Code
Code
Drawing a Circle
The circle method in Python turtle can be used to draw a circle or an arc.
Code Output
1 from turtle import *
2 pensize(4)
3 circle(100, extent=180)
4 hideturtle()
ACTIVITIES
1. Understanding the use of Pen
3
Controls and Pen Control Methods
2. Activity 1 - Identifying the Methods
PEN CONTROL 3. Demo 1 - Draw a House
4. Activity 2 - Drawing Flag Boundary
5. Activity 3 - Drawing Olympic Ring
Activity 1 - Solution
The methods used in the program are as the following:
bgcolor(“blanched almond “)
pencolor(“red”)
pencolor(“blue”)
pensize(6)
pensize(3)
forward(100)
circle(100)
left(90)
penup()
moves the turtle
forward(100) →
to a new position
pendown()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
Demo 1 - Solution
Code
1 from turtle import * 11 left(90) 21 right(90)
2 pensize(5) 12 forward(150) 22 forward(80)
3 penup() 13 left(90) 23 left(90)
4 goto(-100,0) 14 penup() 24 penup()
5 pendown() 15 goto(-20,0) 25 goto(-130,150)
6 forward(200) 16 pendown() 26 pendown()
7 left(90) 17 left(90) 27 forward(260)
8 forward(150) 18 forward(80) 28 goto(0,200)
9 left(90) 19 right(90) 29 goto(-130,150)
10 forward(200) 20 forward(40) 30 penup()
Activity 2 - Solution
Code
1 from turtle import * 10 forward(300)
2 pensize(3) 11 right(146)
3 shape("turtle") 12 forward(360)
4 penup() 13 left(180)
5 goto(-200,0) 14 forward(360)
6 pendown() 15 right(124)
7 left(90) 16 forward(200)
8 forward(200) 17 right(90)
9 right(90) 18 forward(300)
Activity 3 - Solution
Code
1 from turtle import * 10 goto(0, -25) 19 penup()
2 pensize(5) 11 pendown() 20 goto(-55, -75)
3 color("blue") 12 circle(45) 21 pendown()
4 penup() 13 color("red") 22 circle(45)
5 goto(-110, -25) 14 penup() 23 color("green")
6 pendown() 15 goto(110, -25) 24 penup()
7 circle(45) 16 pendown() 25 goto(55, -75)
8 color("black") 17 circle(45) 26 pendown()
9 penup() 18 color("yellow") 27 circle(45)
ACTIVITIES
1. Understanding Color Control
Methods
4 2. Demo - Colouring a Circle
3. Activity 1 - Coloring a Circle
COLOUR FILL 4. Activity 2 - Colouring Bhutan Flag
5. Activity 3 - Check Your
Understanding
6. Activity 4 - Drawing a YouTube
logo
Code
1 from turtle import *
2 shape("turtle")
3 begin_fill()
4 color("purple")
5 circle(50)
6 end_fill()
Activity 1 - Solution
1 from turtle import * 16 penup()
2 pensize(5) 17 forward(100)
3 shape("turtle") 18 pendown()
4 penup() 19 color("purple", "orange")
5 goto(-150,0) 20 begin_fill()
6 pendown() 21 circle(40)
7 color("pink") 22 end_fill()
Code
8 begin_fill() 23 penup()
9 circle(40) 24 forward(100)
10 end_fill() 25 pendown()
11 penup() 26 color("purple", "orange")
12 forward(100) 27 pensize(9)
13 pendown() 28 begin_fill()
14 color("blue") 29 circle(40)
15 circle(40) 30 end_fill()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
Activity 2 - Solution
Code
1 from turtle import * 11 left(90) 21 begin_fill()
2 pensize(3) 12 forward(200) 22 left(180)
3 shape("turtle") 13 right(90) 23 forward(360)
4 penup() 14 forward(300) 24 right(124)
5 goto(-200,0) 15 right(146) 25 forward(200)
6 pendown() 16 forward(360) 26 right(90)
7 fillcolor(“yellow”) 17 end_fill() 27 forward(300)
8 begin_fill() 18 fillcolor(”orange”) 28 end_fill()
2. In the turtle module, what happens if you call end_fill() without first calling
begin_fill()?
Ans: If you forget to call begin_fill() before using end_fill(), the turtle
assumes that there is no shape to fill, and as a result, the colour filling
process doesn't take place.
3. What is the default colour used for filling shapes if fillcolor() is not explicitly
set? (Choose the correct answer from the option given)
a) Red b) Green c) Black
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
Activity 4 - Solution
1 from turtle import * 13 forward(100)
2 speed(0) 14 circle(20,90)
3 pensize(5) 15 end_fill()
4 color("red") 16 penup()
5 goto(-100,0) 17 goto(20,70)
Code
6 begin_fill() 18 pendown()
7 forward(160) 19 color("white")
8 circle(20,90) 20 begin_fill()
9 forward(100) 21 left(90)
10 circle(20,90) 22 circle(40,360,3)
11 forward(160) 23 end_fill()
12 circle(20,90) 24 hideturtle()
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
ACTIVITIES
1. Understanding Text Control
Methods
5 2. Demo - Labelling a Circle
3. Activity 1 - Colouring the House
TEXT METHODS 4. Activity 2 - Drawing a Smiley face
5. Activity 3 - Check Your
Understanding
6. Activity 4 - Drawing Sunset
Text Methods
write() method in Python turtle module is used to write a text on the turtle
canvas.
Example
Method Alignment of the text
write(“Hello World!”,align="center",font=("Arial",16,"normal"))
Demo - Solution
Code
1 from turtle import *
2 pencolor("red")
3 circle(100)
4 penup()
5 goto(0,100)
6 pendown()
7 color("blue")
8 write("Circle", align="center", font=("Georgia",16,"bold"))
Activity 1 - Solution
6 fillcolor("pink")
Code 7 begin_fill()
1 from turtle import * 8 forward(200)
2 pensize(5) 9 left(90)
10 forward(150) Set the
3 penup()
11 left(90) color of the
4 goto(-100,0)
12 forward(200) wall, fill and
5 pendown()
13 left(90) draw the
14 forward(150) wall.
15 left(90)
Import the turtle module, set 16 end_fill()
the pensize, set the position of 17 penup()
the turtle
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
31 goto(-130,150)
32 pendown()
33 fillcolor("green")
34 begin_fill() Set the position to draw
35 forward(260) the roof, select the color
36 goto(0,200) to fill the roof, then draw
37 goto(-130,150) and fill the roof.
38 penup() Add text ‘A house’ using
39 end_fill() write() method.
40 penup()
41 goto(0,-40)
42 color("blue")
43 write("A house!",align="center",font=("Georgia",22))
2. How can you set the turtle's speed to the maximum in the turtle module?
a) set_speed("fastest") b) speed("fastest")
c) max_speed() d) turbo_mode()
3. The size (width, height) method sets the title of the turtle graphics window.
(True/False)
5. The method that sets the background color of the turtle graphics window
is bgcolor("_____").
color (Fill in the blanks)
Activity 4 Solution
Code
1 from turtle import* 15 right(90)
2 title("Sunset") 16 forward(200)
3 shape("turtle") 17 right(90)
4 bgcolor("cyan") 18 forward(400)
5 begin_fill() 19 right(90)
6 color("yellow") 20 forward(200)
7 left(90) 21 right(90)
8 circle(75, 180) 22 forward(200)
9 end_fill() 23 end_fill()
10 home() 24 home()
11 begin_fill() 25 penup()
12 color("blue") 26 goto(0,130)
13 forward(200) 27 pendown()
14 forward(200) 28 write("Sunset",font=("Impact",30))
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX
Key
Points
● Turtle is a built-in module for drawing graphics in Python.
● There are two ways to import turtle: import turtle and from turtle import *
● We can customize turtle window using setup(x, y), title(" "), shape("turtle"),
bgcolor("color"), showturtle(), hideturtle() methods.
● We can manage drawing on turtle with forward(), backward(), left(), and
right(), penup(), pendown(), and customize pen attributes.
● The write( ) method is used to insert text on the turtle canvas.
● The immediate visual feedback in turtle can make programming more
engaging and intuitive, especially for younger learners or those new to coding.
བཀྲིན་ཆེ།
THANK YOU