【问题标题】:Turtle Elements Won't Show Up In Developed Window海龟元素不会出现在开发的窗口中
【发布时间】:2021-11-23 07:41:45
【问题描述】:

所以我试图从乒乓球程序中汲取灵感,制作一个迷宫程序。一切都很好,直到乌龟摔断了。 python 版本是 3.9.7,下面是代码,以及运行代码产生的窗口截图。

import turtle


#Screen: Should be 800 X 600 box, with blue background, and a title of "Test"
wn = turtle.Screen()
wn.title("Test")
wn.bgcolor("blue")
wn.setup(width=800, height=600)
wn.tracer(0)

#Simple character/shape, square, red.
character = turtle.Turtle()
character.speed(0)
character.shape("square")
character.color("red")
character.penup()
character.goto(0, 0)

#main loop
turtle.mainloop()

下面是窗口的图片。如您所见,字符从 0、0 中丢失。我该如何解决这个问题?代码有问题吗?我必须重新安装一些东西吗? [1]:https://i.stack.imgur.com/LMclH.png

【问题讨论】:

  • 删除tracer() 电话,你会看到你的角色。在您的代码基本正常工作之前,请不要再使用 tracer()update()

标签: python python-3.x turtle-graphics python-turtle


【解决方案1】:

你不得不说:

while True:
     wn.update()

不是:

turtle.mainloop()

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 2019-04-23
    • 2019-07-12
    相关资源
    最近更新 更多