简体   繁体   English

如何两次使用python 3乌龟

[英]How do I use a python 3 turtle twice

I am wondering how to use a turtle twice, I use the desired turtle as normal, which works but when I use the same turtle again (after resetting the turtle) every thing goes wrong. 我想知道如何两次使用乌龟,我可以像往常一样使用所需的乌龟,它可以工作,但是当我再次使用同一只乌龟(在重置乌龟之后)时,所有事情都会出错。 What am I doing wrong? 我究竟做错了什么?

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

Yes, I've googled it. 是的,我已经用谷歌搜索了。 No, It didn't help. 不,这没有帮助。 Thats why I'm here! 那就是为什么我在这里!

It seems that everything goes wrong because of line 13 似乎由于第13行,一切都出现了问题

turtle.bye()

This shuts the turtlegraphics window and then when you want to show again the turtle in line 34 with 这将关闭龟图形窗口,然后当您想再次显示第34行的龟时

title.showturtle() 

this raises an error cause you can't show the turtle when graphics window is shut. 这会引发错误,原因是在关闭图形窗口时无法显示乌龟。

To reset the turtle and reuse it you could use turtle.reset() instead of turtle.bye() 要重置乌龟并重新使用它,可以使用turtle.reset()而不是turtle.bye()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM