我想知道如何使用乌龟两次, 我正常使用所需的乌龟,但是当我再次使用同一只乌龟(重置乌龟之后)时,每件事都出错了。 我究竟做错了什么?
import turtle
import time
title = turtle.Turtle()
title.hideturtle()
title.left(180)
title.forward(310)
title.right(180)
title.forward(600)
title.left(180)
title.forward(599)
title.write("WELCOME TO FUTURE WARS!", font=("Arial", 30, "normal"))
time.sleep(5)
turtle.bye()
name = input("Welcome to FUTURE WARS! What is your name? >")
wannaplay = input( name + ", Are you ready to have a fight? >")
if wannaplay == ("yes") or ("Yes"):
print ("Lets Go!")
time.sleep(3)
print ("WAIT!!")
time.sleep(2)
print ("Let me introduce myself...")
time.sleep(2)
print ("My name is Mineblock! I shall be your trainer!")
time.sleep(3)
print ("Now, without any delay, (hopefully) LETS GO!")
time.sleep(3)
else:
print ("What are you doing here, then?")
time.sleep(1)
exit()
print ("Your first battle is against...")
time.sleep(2.8)
title.showturtle()
title.left(180)
title.forward(310)
title.right(180)
title.forward(600)
title.left(180)
title.forward(599)
title.write("Mineblock, Your Trainer", font=("Arial", 30, "normal"))
time.sleep(5)
turtle.bye()
是的,我用谷歌搜索了它。不,它没有帮助。那就是为什么我在这里!
答案 0 :(得分:2)
由于第13行似乎一切都出错了
turtle.bye()
这会关闭turtlegraphics窗口,然后当你想再次显示第34行的龟时
title.showturtle()
这会引发错误,因为在关闭图形窗口时无法显示乌龟。
要重置乌龟并重复使用,您可以使用turtle.reset()
代替turtle.bye()