如何修复python中的属性错误?

问题描述 投票:0回答:3

我是Python新手,目前正在学习对象和图形。我成功导入了graphics.py文件,但由于某种原因,每当我尝试运行

GraphWin
时,它总是给我一个属性错误。请看下面:

import graphics
win = graphics.GraphWin()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'graphics' has no attribute 'GraphWin'

我正在使用 Zelle 的“Python 编程:计算机科学简介”,它很有帮助。

请指教。

python graphics zelle-graphics
3个回答
0
投票

graphics.py 与您遇到错误的文件是否相同?

另外,尝试一下

from graphics import * 
代替
import graphics 


0
投票

我查看了这篇文章,事实证明它很有帮助。我只需创建一个扩展,将特定的子模块添加到模块文件夹中。在这种情况下是:

from graphics._init_ import *
win = GraphWin()

这解决了属性错误。但是,它仅适用于 from import * 公式,不适用于 import 公式


0
投票

这对我有用:

pip 安装graphics.py

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