跟踪3点击房屋代码

时间:2014-11-30 20:00:55

标签: python

我是python的新手,我收到了无效的语法(请参阅下面的错误)我很抱歉这个错误....帮助?我正在编写代码,通过4次点击构建一个房子。下面的很多代码都是我尝试不同的东西,所以请忽略它(或者给我一些我应该做的建议)这是我难以理解的p2错误。

<using graphics.py>
import graphics
from graphics import*

def house():
    win=GraphWin(800,500)
    win.setCoords(0.0,0.0,4.0,4.0)#reset coordinates
    Text(Point(2.0,3.5),"click spot to designate 2 corners of house").draw(win)
    p1=win.getMouse()
    p1.draw(win)
    side1=(Point(p1.getX(),(p1.getY()))
    p2=win.getMouse()<----------------------------ERROR with the p2
    p2.draw(win) 
    side2=(Point(p2.getX(),(p2.getY()))
    rect = Rectangle(side1,side2)
    rect.draw(win)

    #door- p3=center top edge of door
    msg2 = Text(Point(2.0,0.5),"click to designate top of door")
    msg2.draw(win)
    p3=win.getMouse()
    p3.draw(win)
    #golden:)
    Line(Point(p3.getX(),(p3.getY())),(Point(p2.getX()),(p2.getY()))).draw(win)
    """
    p3 = dwidth.getCenter()                             
    rectWidth = (p2.getX()) - (p1.getX())
    #doorWidth = door.setWidth(distance/5.0)#width 1/5 of house 
    dwidth= eval((rectWidth) / (5))
    dheight=((getP3(),(getP2()))#height = from top corners to bottom of the frame
    #door = Rectangle((dwidth) * (dheight))"""
    #door.draw(win)

    """#Window
    message3 = Text(Point(2.0, 1.0),"click to designate center of square     window").draw(win)
    p4=win.getMouse()
    p4.draw(win)
    c=door.getCenter()
    dx=p4.getX()-c.getX()
    dy=p4.getY()-c.getY()
    window = Rectangle(Point(dx,dx),Point(dy,dy))
    window.draw(win)
    #window side = half of door with
    #roof top = half way btwn l and r edges
    #house height = half height of house frame 
    #win.getMouse()
    #win.close
    """
    #window one forth of the door
    #window = Rectangle(p4)
    #window.setWidth(doorwidth/ 4.0)
    #window.draw(win)
house()



>>> ================================ RESTART ================================
>>> 
Traceback (most recent call last):
  File "E:\ICS 140\ass 8.py", line 57, in <module>
    house()
  File "E:\ICS 140\ass 8.py", line 28, in house
    Line(Point(p3.getX()),(p3.getY()),(Point(p2.getX()),(p2.getY()))).draw(win)
TypeError: __init__() missing 1 required positional argument: 'y'
>>> 

1 个答案:

答案 0 :(得分:0)

发生错误是因为Point需要xy参数,但您只是在尝试创建{的行中传递了x {1}}。

不完全确定您的代码尝试做什么,但希望这有助于您开始朝着正确的方向前进:

Rectangle