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()
1turtle.write(arg, move=False, align=’left’, font=(‘Arial’, 8, ‘normal’))
2
3arg Info, which is to be written to the TurtleScreen
4
5align One of the strings “left”, “center” or right”
6
7font A tuple (fontname, fontsize, fonttype)
1import turtle
2
3t = turtle.Turtle()
4t.write(arg = "Hello there",font = ("Calibri",16,"bold"))