2017-05-31 8 views
0

私はユーザが四角形を描き、周囲と面積を計算するプログラムをコーディングしています。 2辺の長さを見つけるのに、私はAttributeError: Rectangle instance has no attribute 'y'を得ます。ここでAttributeError:Rectangleインスタンスに属性 'y'がありません

は、これまでの私のコードです:

from graphics import* 

win=GraphWin('Rectangle',800,800) 

def twopoints(): 
    pRight=win.getMouse() 
    pRight.draw(win) 
    pLeft=win.getMouse() 
    pLeft.draw(win) 
    print (pLeft) 
    print (pRight) 

    rec=Rectangle(pRight,pLeft) 
    rec.draw(win) 
    rec.setFill('red') 
    return pRight, pLeft, rec 

p1=Point(400, 100) 
m=Text(p1,"Click two places on the screen to create a rectangle") 
m2=Text(Point(400, 150), "Your first click will be the upper right corner") 
m3=Text(Point(400, 200), "Your second click will be the bottom left corner") 
m.draw(win) 
m2.draw(win) 
m3.draw(win) 

rec, pRight, pLeft=twopoints() 

m.setText("Click to get either the area or perimeter") 
m2.undraw() 
m3.undraw() 

side1=abs(pLeft.y-pRight.y) 
side2=abs(pLeft.x-pRight.x) 
print (side1) 

答えて

0

あなたが重要であるに複数のものを返すため。ここでは、

return pRight, pLeft, rec 

しかし、そのようにpLeft外の実際の内部recと同じであり、唯一の順序によって、ここに名前でこれらが一致しない

rec, pRight, pLeft=twopoints() 

のPythonに割り当てます。

+0

ありがとうございます! – mslee

関連する問題