【发布时间】:2020-09-05 10:00:01
【问题描述】:
我制作了一个单独的 python 文件来创建对象类。比我将这个类导入另一个文件并制作这个 pad1 对象。
pad1 = Object("square", "blue", -350, 0)
pad1.shapesize(stretch_len=1,stretch_wid=5)
但我收到一条错误消息:“对象”对象没有属性“_outlinewidth”
对象类代码
import turtle
from turtle import Turtle
class Object(Turtle):
def __init__(self, shape, color, x, y):
self = Turtle()
self.speed(0)
self.shape(shape)
self.color(color)
self.penup()
self.goto(x, y)
我该如何解决这个问题?我想使用单独的文件和使用类来解决这个问题,类似于我尝试过的方式
【问题讨论】:
-
super().__init__()而不是self = Turtle()。见Inheritance 和super()。
标签: python class inheritance turtle-graphics attributeerror