为什么Python中的turtle模块在尝试访问它时似乎具有屏幕属性会导致属性错误?

问题描述 投票:-2回答:1

以下是试图使用Python turtle模块绘制乌龟图形的脚本。

import turtle

wn = turtle.screen()

alex = turtle.Turtle()

alex.forward(50)

alex.left(90)

alex.forward(30)

wn.mainloop()

在运行时,脚本产生以下回溯(具有脚本的通用路径)。

Traceback (most recent call last):
  File "</path/to/script>.py", line <number>, in <module>
    wn = turtle.screen()
AttributeError: module 'turtle' has no attribute 'screen'

[turtle模块似乎在其screen中具有documentation属性。既然如此,为什么会出现此AttributeError

python turtle-graphics traceback
1个回答
0
投票

您收到错误

Traceback (most recent call last):
  File "</path/to/script>.py", line <number>, in <module>
    wn = turtle.screen()
AttributeError: module 'turtle' has no attribute 'screen'

因为turtle库没有属性screen,但这只是一个小的错字,因为turtle库does具有Screen属性。 Python编程语言关心字母的大小写,通常将其描述为区分大小写的语法case sensitivity

© www.soinside.com 2019 - 2024. All rights reserved.