1import turtle
2
3# Create the window
4wn = turtle.Screen()
5wn.setup(800, 600) # Dimensions
6wn.bgcolor("black") # Background color
7wn.title("Window") # Title
8
9# Main loop
10while True:
11 window.update() # Update window
1import turtle
2
3wn = turtle.Screen()
4wn.setup(width=700,height=400)
5wn.title("Python Turtle Movement")
6
7def playerUp():
8 player.sety(player.ycor()+10)
9def playerDown():
10 player.sety(player.ycor()-10)
11def playerRight():
12 player.setx(player.xcor()+10)
13def playerLeft():
14 player.setx(player.xcor()-10)
15
16player = turtle.Turtle()
17player.speed(0) #this will make your player created instantly
18player.shape("square") #set player shape
19player.color("red") #set player color
20player.penup() #prevent drawing lines
21player.goto(0,0) #set player location
22
23wn.onkeypress(playerUp, "w") #function, key
24wn.onkeypress(playerDown, "s")
25wn.onkeypress(playerRight, "d")
26wn.onkeypress(playerLeft, "a")
27
28#update the window
29while True:
30 wn.update()
1def turtle_triangle():
2 window = turtle.Screen()
3 window.bgcolor("red")
4
5 brad = turtle.Turtle()
6
7 brad.shape("turtle")
8 brad.color("yellow")
9 brad.speed(1)
10
11 for _ in range(3):
12 brad.right(60)
13 brad.forward(200)
14 brad.right(60)
15
16 window.exitonclick()
1import turtle
2t = turtle.Turtle()
3t.color(color) # choose a color
4t.begin_fill() # if you want it to be filled with color later
5t.circle(10) # the function "circle" and the radious.
6t.end_fill() # completing the filling of the circle.
7# try to do it and see if it works. it worked for me.
1>>> turtle.home()
2>>> turtle.position()
3(0.00,0.00)
4>>> turtle.heading()
50.0
6>>> turtle.circle(50)
7>>> turtle.position()
8(-0.00,0.00)
9>>> turtle.heading()
100.0
11>>> turtle.circle(120, 180) # draw a semicircle
12>>> turtle.position()
13(0.00,240.00)
14>>> turtle.heading()
15180.0
16