【问题标题】:Jython "Attribute not found"Jython“找不到属性”
【发布时间】:2015-10-16 01:27:01
【问题描述】:

我正在尝试在 v3.4 上使用 JES 中的一些 tkinter 功能。但是导入后出现错误。

代码以此开头:

import Turtle
import math
myPen = Turtle.turtle()
window = Turtle.screen()

返回错误

错误是:类 'Turtle' 没有属性 'turtle'
未找到属性。

(请注意,我使用“Turtle”而不是“turtle”的正确版本(3.4.3)python)
import turtle 给出The error was: turtle (wrong name: Turtle)

我按照类似线程的建议在 Python 控制台中尝试了一些故障排除,结果如下。我相信输出应该是 "turtle.py" 或类似的,但正如您所见,它不起作用。

>>> import sys
>>> sys.path
['', 'C:\\Windows\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\
\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages']
>>> import turtle
>>> turtle.__file.__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file'
>>>

按照路径C:\Python34\Lib我发现有一个文件夹C:\Python34\Lib\turtledemo包含文件turtle.cfg但没有turtle.py
同样C:\Python34\DLLs 包含_tkinter.pyd(和许多其他)但没有_turtle.pyd

我只是一个试图在 JES 中使用turtle 进行项目的学生,所以我希望这个问题有意义。

【问题讨论】:

    标签: python module tkinter turtle-graphics jes


    【解决方案1】:

    您的问题是您正在寻找模块中的屏幕。您必须创建一个海龟对象。那将具有屏幕属性。我正在使用 CPython 3.5 和 import turtle 工作。

    >>> import turtle
    >>> t = turtle.Turtle()
    >>> t.screen
    <turtle._Screen object at 0x10cd25a20>
    

    您可能需要在您的平台上进行修改。

    【讨论】:

    • import Turtle 后跟myPen = turtle.Turtle() 给出The error was:class 'Turtle' has no attribute 'Turtle' ==== 仍然是同样的问题,我已经尝试了大写等的所有组合......还有其他想法吗?
    • 对不起,我没有。我不使用 JES(也不是 Jython),显然,它与 CPython 有一些我不理解的差异。我试过谷歌搜索,但我没有找到任何证据表明 JES 乌龟甚至具有屏幕属性。
    • 我将把它归结为 JES 中的限制。反正也不是什么太重要的问题。 @saulspatz Thank you for you time on this
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多