Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+3 votes

below is my code for my final project. I am getting an error that says AttributeError: 'NoneType' object has no attribute 'draw'. I was wondering if anyone knows how to fix this

class Rectangles:
    #9 different squares will appear with the values 1-9
    def __init__(self, point1, point2, point3, point4):
        self.rectangle = Rectangle(Point(point1, point2), Point(point3, point4))
        self.rectangle.setFill("brown")
    
    def draw(self, win):
        self.rectangle.draw(win)
        
        
def setupRectangle():
    rect1 = Rectangles(0,900,100,400)

def main():
    win = GraphWin("Shut The Box",WINDOW_WIDTH, WINDOW_HEIGHT)
    win.setBackground("green")
    rect = setupRectangle()
    rect.draw(win)
    #rect.draw(win)

if __name__ == '__main__':
    main()
asked in CSC201 Spring 2021 by (1 point)
edited by
+1

Note: edited question to use {} button to format it as code.

1 Answer

+3 votes

I think you'll want to return rect1 in setupRectangle, because right now rect doesn't equal anything, it only calls setupRectangle. That's why rect won't draw anything, because it doesn't equal anything.

answered by (1 point)
...