【问题标题】:Turtle issue with vs code [closed]vs代码的乌龟问题[关闭]
【发布时间】:2021-12-17 02:19:31
【问题描述】:

您好,这是我第一次尝试用 python 编写视频游戏。 所以我找到了一个教程视频,它与我的(mac)在同一操作系统上运行,但是当我在视频中编写设置时:

#Setup
import turtle

wn=turtle.Screen
wn.title("Pong")
wn.bgcolor("black")
wn.setup(width=800, heigth=600)
wn.tracer(0)

#Main game loop
while True:
    wn.update()

出现了这个错误:

AttributeError: 'function' object has no attribute 'title'

有人知道这意味着什么以及如何解决吗? 顺便说一句,我正在运行 python 3.10.0

【问题讨论】:

  • turtle.Screen 是一个函数。 turtle.Screen() 调用该函数并返回一个窗口对象,该对象具有您尝试调用的方法。

标签: python visual-studio-code attributeerror python-turtle python-3.10


【解决方案1】:

t1

试试这个

#Setup
import turtle

wn=turtle.Screen()#call the Screen like: Screen()
wn.title("Pong")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)

#Main game loop
while True:
    turtle.update()

有用吗??

【讨论】:

  • 是的,谢谢伙计!!!
  • 对问题的回答应该提供对问题和/或解决方案的解释,而不仅仅是包含代码。
  • 它有效,但窗口只出现了几分之一秒。有什么建议吗?
  • 你是否使用过,如果不使用,则为真。
  • 我在程序结束时使用了 while true 但它仍然不起作用
【解决方案2】:

的 t1 没有工作试试这个

#Setup
import turtle

wn=turtle.Screen()#call the Screen like: Screen()
wn.title("Pong")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)

#Main game loop
turtle.done()

尝试使用完成而不是更新
没事吧??

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    • 2017-08-09
    • 1970-01-01
    • 2010-11-03
    • 2014-03-01
    相关资源
    最近更新 更多