微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使一个方面消失

如何解决使一个方面消失

我正在用 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()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。