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

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

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()

 

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在turtle分类目录。将固定链接加入收藏夹。