操作矩形上下左右移动的代码

"""操作矩形上下左右移动的代码"""

from turtle import *

def 向上移():

    y = t.ycor() + 10
    t.sety(y)

def 向下移():

    y = t.ycor() - 10
    t.sety(y)

def 向左移():

    x = t.xcor() - 10
    t.setx(x)

def 向右移():

    x = t.xcor() + 10
    t.setx(x)
  
screen = Screen()

t = Turtle(shape='square')
t.penup()
t.color("magenta")
t.shapesize(1,10)

screen.onkeypress(向上移,"Up")
screen.onkeypress(向下移,"Down")

screen.onkeypress(向左移,"Left")

screen.onkeypress(向右移,"Right")

screen.listen()