使一个方面消失

问题描述

我正在用 python 制作乒乓球游戏,我试图让文本出现几秒钟然后消失,有人能帮我解决这个问题吗:

Instructions.speed(0)
Instructions.color("green")
Instructions.penup()
Instructions.hideturtle()
Instructions.goto(0,-260)
Instructions.color("red")
Instructions.write("W,A and arrow keys to move",align="center",font=("Courier",36,"normal"))

我还需要添加什么?

解决方法

写完文本后,我们可以发起一个屏幕ontimer事件来调用乌龟的clear()方法来擦除文本。例如:

from turtle import Screen,Turtle

screen = Screen()

turtle = Turtle()
turtle.hideturtle()
turtle.color('red')
turtle.penup()
turtle.sety(-260)

turtle.write("W,A and arrow keys to move",align='center',font=('Courier',36,'normal'))
screen.ontimer(turtle.clear,2000)  # milliseconds in the future

screen.mainloop()