turtle background color python code example
Example 1: how to change background color in python turtle
import turtle
wn=turtle.Screen()
wn.bgcolor("black")
wn.title("This is my screen title!")
Example 2: python turtle movement
import turtle
wn = turtle.Screen()
wn.setup(width=700,height=400)
wn.title("Python Turtle Movement")
def playerUp():
player.sety(player.ycor()+10)
def playerDown():
player.sety(player.ycor()-10)
def playerRight():
player.setx(player.xcor()+10)
def playerLeft():
player.setx(player.xcor()-10)
player = turtle.Turtle()
player.speed(0)
player.shape("square")
player.color("red")
player.penup()
player.goto(0,0)
wn.onkeypress(playerUp, "w")
wn.onkeypress(playerDown, "s")
wn.onkeypress(playerRight, "d")
wn.onkeypress(playerLeft, "a")
while True:
wn.update()
Example 3: turtle write
turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))